【发布时间】:2017-03-26 23:09:31
【问题描述】:
我正在使用最新版本的 Play 框架,以及来自 build.sbt 文件的以下测试依赖项:
"org.scalatest" %% "scalatest" % "3.0.0",
"org.scalatestplus.play" % "scalatestplus-play_2.11" % "2.0.0-M1"
我的所有测试用例都扩展自一个基本规范。我在每个子句中返回一个Future[Assertion],它看起来像这样:
trait BaseSpec extends AsyncWordSpec with TestSuite with OneServerPerSuite with MustMatchers with ParallelTestExecution
示例规范如下所示:
"PUT /v1/user/create" should {
"create a new user" in {
wsClient
.url(s"http://localhost:${port}/v1/user")
.put(Json.obj(
"name" -> "username",
"email" -> "email",
"password" -> "hunter12"
)).map { response => response.status must equal(201) }
}
}
我决定使用较新版本的ScalaTest 提供的AsyncWordSpec 重写我当前的测试,但是当我运行测试套件时,我得到的输出如下:
[info] UserControllerSpec:
[info] PUT /v1/user/create
[info] application - ApplicationTimer demo: Starting application at 2016-11-13T01:29:12.161Z.
[info] application - ApplicationTimer demo: Stopping application at 2016-11-13T01:29:12.416Z after 1s.
[info] application - ApplicationTimer demo: Stopping application at 2016-11-13T01:29:12.438Z after 0s.
[info] application - ApplicationTimer demo: Stopping application at 2016-11-13T01:29:12.716Z after 0s.
[info] application - ApplicationTimer demo: Stopping application at 2016-11-13T01:29:13.022Z after 1s.
[info] ScalaTest
[info] Run completed in 13 seconds, 540 milliseconds.
[info] Total number of tests run: 0
[info] Suites: completed 4, aborted 0
[info] Tests: succeeded 0, failed 0, canceled 0, ignored 0, pending 0
[info] No tests were executed.
[info] Passed: Total 0, Failed 0, Errors 0, Passed 0
[success] Total time: 20 s, completed Nov 12, 2016 8:29:13 PM
我的所有测试类都是在调用sbt test 时由测试运行程序找到、构建和运行的。我也尝试过使用 IDEA 测试运行器,它会在我的每个测试类下报告 Empty Test Suite。我已经详尽地尝试了 RTFM,但我看不出我做错了什么。我的测试的同步版本运行良好。
编辑 1:一位朋友建议尝试在我的 Future[WSResponse] 上执行 whenReady() { /* clause */ },但这也失败了。
【问题讨论】:
标签: scala playframework scalatest