【问题标题】:ScalaTest: Suites are being executed but no test cases are actually running?ScalaTest:正在执行套件,但实际上没有运行测试用例?
【发布时间】: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


    【解决方案1】:

    我在使用具有多个特征的测试套件时遇到了同样的问题。我通过删除除AsyncFlatSpec 之外的所有其他特征来使其工作。我会根据需要一次添加一个。

    【讨论】:

    • 删除 with MockitoFixture 使测试为我运行。
    • MockFactory (ScalaMock) 对我来说是个问题。 Matchers, LoneElement 可以混入没有任何问题。
    猜你喜欢
    • 2015-01-02
    • 2017-05-22
    • 1970-01-01
    • 2015-07-10
    • 2014-04-28
    • 2019-07-27
    • 2021-03-06
    • 1970-01-01
    • 2018-12-07
    相关资源
    最近更新 更多