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.
Published to Maven Central. Example dependency in sbt on the play28-specific artifact:
libraryDependencies += "com.rallyhealth" %% "play28-test-ops-core" % "version"
Scala Versions supported:
Artifact | Scala 2.11 | Scala 2.12 | Scala 2.13 | Scala 3 |
---|---|---|---|---|
play25-test-ops-core | ✅ | |||
play26-test-ops-core | ✅ | ✅ | ||
play27-test-ops-core | ✅ | ✅ | ✅ | |
play28-test-ops-core | ✅ | ✅ | ||
play29-test-ops-core | ✅ | ✅ | ||
play30-test-ops-core | ✅ | ✅ |
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
}
}
}
}