ScalaTest / SBT "testOnly com.acme.someText -- -n Slow" 忽略所有测试

ScalaTest / SBT "testOnly com.acme.someText -- -n Slow" ignores all tests

我正在尝试使用 ScalaTest 的标记功能来限制测试套件中的测试范围 运行。不幸的是,它根本不起作用;我尝试过的任何语法都只会导致 根本没有测试 运行ning.

import org.scalatest.tagobjects._
"Ship service" should {
    "return to port" taggedAs(Slow) in {
        whenReady(client.getShip(shipId).invoke()) { ship =>
            whenReady(client.dock(ship.id).invoke()) { response =>
                response should be(Done)
            }
        }
    }
}

我也尝试过使用 "return to port" taggedAs(org.scalatest.tagobjects.Slow),但没有任何区别。

当我尝试 运行 在 SBT 中只进行 Slow 测试时,没有测试 运行:

sbt:ship-service> testOnly "com.acme.ship.ShipSpec -- -n org.scalatest.tagobjects.Slow"
[info] ScalaTest
[info] Run completed in 13 milliseconds.
[info] Total number of tests run: 0
[info] Suites: completed 0, aborted 0
[info] Tests: succeeded 0, failed 0, canceled 0, ignored 0, pending 0
[info] No tests were executed.

我也试过:

sbt:ship-service> testOnly "com.acme.ship.ShipSpec -- -n Slow"
sbt:ship-service> testOnly com.acme.ship.ShipSpec -- -n Slow

与第一个没有区别。在第二个(不带引号)上,每个测试 运行,无论应用的标签如何(因此所有测试,包括未标记和标记)。

假设您使用的是 org.scalatest.tagobjects.Slow 而不是实现为 object Slow extends Tag("org.scalatest.tags.Slow") 所以您需要执行 testOnly com.acme.ship.ShipSpec -- -n org.scalatest.tags.Slow 或定义您自己的标签 fe: case object Slow extends Tag("Slow")