ScalaTest runner + FunSuite + 标签 : can't get `-n` and `-l` to include/exclude tag?

标签 scala scalatest

ScalaTest runner 应该支持通过标签包含或排除测试,但我无法让它工作。我究竟做错了什么?详情如下。

在一个空目录中,给定 build.sbt:

libraryDependencies += "org.scalatest" %% "scalatest" % "2.1.0" % "test"

和 src/test/scala/Test.scala:

class Test extends org.scalatest.FunSuite {
  test("fast") {
    assertResult(4)(2 + 2) }
  test("slow", org.scalatest.tagobjects.Slow) {
    assertResult(40)(20 + 20) }
}

然后:

% sbt
[info] Set current project to bug (in build file:/Users/tisue/bug/)
> show sbtVersion
[info] 0.13.1
> test
[info] Compiling 1 Scala source to /Users/tisue/bug/target/scala-2.10/test-classes...
[info] Test:
[info] - fast
[info] - slow
[info] Run completed in 192 milliseconds.
[info] Total number of tests run: 2
[info] Suites: completed 1, aborted 0
[info] Tests: succeeded 2, failed 0, canceled 0, ignored 0, pending 0
[info] All tests passed.
[success] Total time: 3 s, completed Mar 15, 2014 12:25:06 PM

到目前为止一切顺利。但是现在:

> test-only Test -- -l org.scalatest.tagobjects.Slow
[info] Test:
[info] - fast
[info] - slow
[info] Run completed in 108 milliseconds.
[info] Total number of tests run: 2
[info] Suites: completed 1, aborted 0
[info] Tests: succeeded 2, failed 0, canceled 0, ignored 0, pending 0
[info] All tests passed.
[success] Total time: 0 s, completed Mar 15, 2014 12:25:39 PM
> test-only Test -- -n org.scalatest.tagobjects.Slow
[info] Test:
[info] Run completed in 93 milliseconds.
[info] Total number of tests run: 0
[info] Suites: completed 1, aborted 0
[info] Tests: succeeded 0, failed 0, canceled 0, ignored 0, pending 0
[info] No tests were executed.
[success] Total time: 0 s, completed Mar 15, 2014 12:25:42 PM

-l排除标签不排除任何东西,用-n包含标签不包含任何东西。

问题不特定于 sbt/ScalaTest 集成,因为如果我直接运行运行器它也会失败:

> test:run-main org.scalatest.tools.Runner -o -R target/scala-2.10/test-classes -l org.scalatest.tagobjects.Slow
[info] Running org.scalatest.tools.Runner -o -R target/scala-2.10/test-classes -l org.scalatest.tagobjects.Slow
Discovery starting.
Discovery completed in 52 milliseconds.
Run starting. Expected test count is: 2
Test:
- fast
- slow
Run completed in 96 milliseconds.
Total number of tests run: 2
Suites: completed 2, aborted 0
Tests: succeeded 2, failed 0, canceled 0, ignored 0, pending 0
All tests passed.

Exception: sbt.TrapExitSecurityException thrown from the UncaughtExceptionHandler in thread "ScalaTest-main"
[success] Total time: 0 s, completed Mar 15, 2014 12:30:14 PM
> test:run-main org.scalatest.tools.Runner -o -R target/scala-2.10/test-classes -n org.scalatest.tagobjects.Slow
[info] Running org.scalatest.tools.Runner -o -R target/scala-2.10/test-classes -n org.scalatest.tagobjects.Slow
Discovery starting.
Discovery completed in 51 milliseconds.
Run starting. Expected test count is: 0
Test:
Run completed in 86 milliseconds.
Total number of tests run: 0
Suites: completed 2, aborted 0
Tests: succeeded 0, failed 0, canceled 0, ignored 0, pending 0
No tests were executed.

Exception: sbt.TrapExitSecurityException thrown from the UncaughtExceptionHandler in thread "ScalaTest-main"
[success] Total time: 0 s, completed Mar 15, 2014 12:30:18 PM

我做错了什么?

最佳答案

您需要使用“org.scalatest.tags.Slow”作为标签名称,如the ScalaDoc for Slow 中所述.

不幸的是,注释和对象不可能具有相同的完全限定名称,因此我们使用注释的完全限定名称作为标签名称。

关于ScalaTest runner + FunSuite + 标签 : can't get `-n` and `-l` to include/exclude tag?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22427343/

相关文章:

scala - scalatest 中的 java.lang.NoClassDefFoundError

Java LinkedHashMap 到 scala Map 转换及递归转换

scala - 如何访问定义位置之外的对象中的累加器?

scala - 为什么我的 scalatest 测试无法编译? (scala.MatchError)

scala - 为SBT中的多个测试文件夹设置操作

scala - 使用 scalatest 测试封装在 Failure() 中的异常类型

scala - Play 应用程序中的规范/scalatest 交互问题

generics - 在 Scala 中获取泛型类型的特定简单名称

scala - 映射和减少/折叠 scalaz.Validation 的 HList

scala - 你如何在 sbt 存储库文件中发表评论?