我需要在运行测试套件时跳过规范和个别测试。 这是一个这样的测试示例:
package models
import org.specs2.mutable._
import org.specs2.runner._
class SlowTaggedSpecification extends Specification{
"SLOW_SPEC" should {
"BAD!! Not Skipped" in {
"axbcd" must find( "bc".r )
}
} section( "SLOW_SPEC" )
}
class SlowFastTaggedSpecification extends Specification{
"SLOW_FAST_SPEC" should {
"run fast test" in {
"axbcd" must find( "bc".r )
} section( "FAST_TEST" )
"SLOW_TEST should be skipped (BAD!! NOT Skipped)" in {
"axbcd" must find( "bc".r )
} section( "SLOW_TEST" )
} section( "SLOW_FAST_SPEC" )
}
我需要跳过 SLOW_SPEC
(整个规范)和 SLOW_TEST
(仅个别测试)。
我的 build.sbt 是:
scalaVersion := "2.11.1"
libraryDependencies += "org.specs2" %% "specs2" % "2.3.12" % "test"
当我运行以下命令行时:
sbt '~testOnly models.* -- -l SLOW_SPEC'
sbt '~testOnly models.* -- -l SLOW_TEST'
没有一个测试被跳过。我可以知道如何使用标签排除规范和单独测试吗?另外,如果我不使用 testOnly
,而是使用 test
,那么 sbt 语法是什么?
sbt '~test -- -l SLOW_SPEC'
导致 sbt 提示。我的sbt版本是0.13.5
如有任何指点,我们将不胜感激。
最佳答案
排除标签的命令行参数是
sbt> ~testOnly models.* -- exclude SLOW_SPEC
如果你想在使用 test
命令时排除标签,你需要在你的 build.sbt
文件中使用 Test.Arguments
:
testOptions in Test += Tests.Argument(TestFrameworks.Specs2, "exclude", "SLOW_SPEC")
如果您想专门运行 SLOW_SPEC 测试,请使用以下命令:
sbt 'set testOptions in Test := Seq()' '~testOnly models.SlowTaggedSpecification'
关于sbt - specs2:标记规范/单独测试并使用 sbt 将其排除在运行之外,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30474711/