如何使用SBT仅运行单个Spec2规范?

16

如果您的SBT项目中定义了2个测试:

class Spec1 extends Specification {
  def is =
    "Tests for specification 1" ^
      p ^
      "Test case 1" ! todo ^
      end
}

class Spec2 extends Specification {
  def is =
    "Tests for specification 2" ^
      p ^
      "Test case 2" ! todo ^
      end
}

那么在 SBT 中运行 test 将执行这两个测试。运行其中一个测试的最简单方法是什么?

在 SBT 中只运行其中一个测试的最简单方法是使用以下命令:

sbt "testOnly *TestClassName*"

将 *TestClassName* 替换为要运行的测试类的名称。

1个回答

19

9
如果您不想先进入sbt shell,可执行文件只接受一个参数,因此您需要在引号中传递整个命令。在这里,使用sbt "test-only com.example.MySpec"sbt "test-only *MySpec" - broadmonkey

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接