![](/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.