我正在使用最新版本的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) }
}
}
我决定使用较新版本AsyncWordSpec
提供的ScalaTest
重写我当前的测试,但是当我运行测试套件时,这是我得到的输出:
[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:朋友建议尝试whenReady() { /* clause */ }
Future[WSResponse]
,但这也失败了。
答案 0 :(得分:0)
在使用具有多个特征的测试套件时,我遇到了同样的问题。我通过删除AsyncFlatSpec
以外的所有其他特征来使其工作。我会在需要时将它们一次添加回去。