Functional testing
Let's look at some of Play's test cases to see how to use the helper methods. For example, consider the DevErrorPageSpec
test, which is defined as follows:
object DevErrorPageSpec extends PlaySpecification{ "devError.scala.html" should { val testExceptionSource = new play.api.PlayException.ExceptionSource("test", "making sure the link shows up") { ... } …. "show prod error page in prod mode" in { val fakeApplication = new FakeApplication() { override val mode = play.api.Mode.Prod } running(fakeApplication) { val result = DefaultGlobal.onError(FakeRequest(), testExceptionSource) Helpers.contentAsString(result) must contain("Oops, an error occurred") } } } }
This test starts FakeApplication
with the Prod mode and checks the response ...
Get Mastering Play Framework for Scala now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.