play25-test-ops-core | play26-test-ops-core | play27-test-ops-core |
---|---|---|
Introduction
Adds Play Framework test code helpers that augment the com.typesafe
%% play-test
library
with the following features:
- AsyncResultExtractors: Instead of blocking for a result, extract the content into Futures and let the testing framework handle it for you.
Usage
The following example uses the AsyncTestSuite
in ScalaTest 3.x along with the
play.api.test.EssentialActionCaller
from the play-test
project:
class MyTest extends AsyncWordSpec
with AsyncResultExtractors
with EssentialActionCaller {
"my test should complete asynchronously" in {
val ctrl = new MyTestController
val testJson = Json.obj("expected" -> "json")
val request = FakeRequest("POST", "/test/json").withJsonBody(testJson)
for {
result <- call(ctrl.testAction, request)
resultBody <- contentAsJson(result)
} yield {
assertResult(testJson) {
resultBody
}
}
}
}