![](/img/trans.png)
[英]How to specify “fork in Test := false” from command line rather than from build.sbt in a play framework based project
[英]How do I specify specific test from the build.sbt
如何从build.sbt文件中指定测试,我只想运行一个测试,并且像sbt docs一样使用过滤器,但是它对我不起作用,这是我的代码,我有两个测试类在我的sbt中,我将test1指定为rub,但是似乎两个测试同时运行,任何人都知道我应该怎么做?
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
如果要从Test1Demo
运行value of x
test的value of x
:
testOnly *Test1Demo -- -z value
此sbt命令将仅运行名称包含子字符串“ value”的测试。
对于完全匹配而不是子字符串,请使用-t
而不是-z
。
注意--
(两个-
,不是一个)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.