如何从build.sbt文件中指定测试,我只想运行一个测试,并且像sbt docs一样使用过滤器,但是它对我不起作用,这是我的代码两个测试类,并且在我的sbt中,我将test1指定为rub1,但是似乎两个测试在同一时间运行,任何人都知道我应该做什么?
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
答案 0 :(得分:2)
如果您要从value of x
运行Test1Demo
测试:
testOnly *Test1Demo -- -z value
此sbt命令将仅运行名称包含子字符串“值”的测试。
要获得完全匹配而不是子字符串,请使用-t
而不是-z
。
请注意--
(两个-
,而不是一个)