如何从 build.sbt 中指定特定测试

How do I specify specific test from the build.sbt

如何从 build.sbt 文件中指定测试,我只想 运行 一个测试并且我使用了 sbt 文档中的过滤器,但它不适用于我,这是我的代码我有两个测试 类 并且在我的 sbt 中我指定 test1 是 rub 但似乎这两个测试同时 运行ning 任何人都知道我应该做什么?

Test1Demo.scala

import org.scalatest.{FlatSpec, Matchers}

class Test1Demo extends FlatSpec with Matchers{
  "value of x " should " be 9 " in { assert(my.App.x == 9) }
}

Test2Demo.scala

import org.scalatest.{FlatSpec, Matchers}

class Test2Demo extends FlatSpec with Matchers{
  "value of y " should " be 8 " in { assert(my.App2.y == 8) }
}

build.sbt

version := "0.1"

scalaVersion := "2.12.8"

libraryDependencies += "org.scalatest" %% "scalatest" % "3.0.5" % Test

testOptions in Test := Seq(Tests.Filter(s => s.startsWith("Test1")))

输出:

[info] Done updating.
[info] Compiling 2 Scala sources to /home/****/target/scala-2.12/classes ...
[info] Done compiling.
[info] Compiling 2 Scala sources to /home/****/target/scala-2.12/test-classes ...
[info] Done compiling.
[info] Test2Demo:
[info] value of y 
[info] - should be 8
[info] Test1Demo:
[info] value of x 
[info] - should be 9
[info] Run completed in 6 seconds, 365 milliseconds.
[info] Total number of tests run: 2
[info] Suites: completed 2, aborted 0
[info] Tests: succeeded 2, failed 0, canceled 0, ignored 0, pending 0
[info] All tests passed.
[success] Total time: 264 s, completed Apr 15, 2019 2:47:10 PM

如果您想 运行 value of xTest1Demo 测试:

testOnly *Test1Demo -- -z value

此 sbt 命令将 运行 仅名称包含子字符串 "value".

的测试

对于精确匹配而不是子字符串,使用 -t 而不是 -z

注意--(两个-,不是一个)