ScalaTest runner + FunSuite +标签:不能让`-n`和`-l`包含/排除标签?

时间:2014-03-15 17:36:32

标签: scala scalatest

ScalaTest运行器应支持按标签包含或排除测试,但我无法使其工作。我究竟做错了什么?详情如下。

在另一个空目录中,给出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

我做错了什么?

2 个答案:

答案 0 :(得分:3)

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

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

答案 1 :(得分:0)

工作示例:

如“标记测试”中的http://doc.scalatest.org/2.1.0/index.html#org.scalatest.FunSuite所述,您必须传递一个扩展org.scalatest.Tag的对象。例如:

import org.scalatest.FlatSpec
import org.scalatest.Tag
import org.scalatest.tags.Slow

object Other extends Tag("com.mycompany.groups.Other")

class Test extends org.scalatest.FunSuite {
  test("fast") {
    assertResult(4)(2 + 2) }

  test("slow", org.scalatest.tagobjects.Slow ) {
    assertResult(40)(20 + 20) }

  test("other", Other){
    assertResult(42)(21 + 21)   }
}