Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/242.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Scala TestOnly和@DoNotDiscover_Scala_Scalatest - Fatal编程技术网

Scala TestOnly和@DoNotDiscover

Scala TestOnly和@DoNotDiscover,scala,scalatest,Scala,Scalatest,我正在从事一个用Scala编写并使用ScalaTest进行单元测试的项目 测试的结构方式是所有测试都封装在套件中。单个测试用例类用属性@DoNotDiscover修饰,这样当有人运行sbt test时,只有套件运行,单个类不会自己运行。然后,该套件将执行作为其一部分的所有测试用例 这很好,但是它的一个副作用是,如果我只测试com.IndividualTestCase,那么我会得到输出 [info] Run completed in 1 second, 142 milliseconds. [inf

我正在从事一个用Scala编写并使用ScalaTest进行单元测试的项目

测试的结构方式是所有测试都封装在套件中。单个测试用例类用属性
@DoNotDiscover
修饰,这样当有人运行
sbt test
时,只有套件运行,单个类不会自己运行。然后,该套件将执行作为其一部分的所有测试用例

这很好,但是它的一个副作用是,如果我只测试com.IndividualTestCase,那么我会得到输出

[info] Run completed in 1 second, 142 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.
[info] No tests to run for test:testOnly
我想要的是,如果有人说
sbt test
,那么只有套件会被执行,而带有
@DoNotDiscover
的类不会被执行

但是如果我特别调用我的测试用例,比如
sbt test only com.IndividualTestCase
,那么sbt只能找到并执行指定的特定测试用例

似乎如果类被标记为
@DoNotDiscover
,那么我们就失去了对单个测试用例进行
测试的能力(我可以轻松地对套件进行测试)

上面说,
ScalaTest将运行带有DoNotDiscover注释的类。如果要求显式地运行,它就不会发现它们。
但我没有这样做。正如您在上面看到的,单个测试用例上的testonly命令没有运行任何测试