【发布时间】:2020-02-07 19:06:45
【问题描述】:
我正在使用Scalatest 3.1.0-SNAP13,但找不到如何从此PR 中指定初始化种子选项。
我正在使用 SBT 运行测试,所以如果有办法在 build.sbt 中指定此选项将是理想的。
【问题讨论】:
标签: scala scalatest property-based-testing
我正在使用Scalatest 3.1.0-SNAP13,但找不到如何从此PR 中指定初始化种子选项。
我正在使用 SBT 运行测试,所以如果有办法在 build.sbt 中指定此选项将是理想的。
【问题讨论】:
标签: scala scalatest property-based-testing
-S 标志在 3.1.x 中似乎是 disabled:
parseLongArgument(seedArgs, "-S") match {
case Some(seed) => // Randomizer.defaultSeed.getAndSet(Some(seed))
println("Note: -S for setting the Randomizer seed is not yet supported.")
case None => // do nothing
}
不过在 3.2.x 中好像是enabled,所以试试
libraryDependencies += "org.scalatest" %% "scalatest" % "3.2.0-M1" % Test
和
testOptions in Test += Tests.Argument(TestFrameworks.ScalaTest, "-S", "1568769615146")
【讨论】:
我设法让它工作:
// specify an initial seed 0
Test / testOptions += Tests.Argument(TestFrameworks.ScalaTest, "-S", "0")
结果:
[info] SummaryTest:
[info] - hello *** FAILED *** (49 milliseconds)
[info] GeneratorDrivenPropertyCheckFailedException was thrown during property evaluation. (SummaryTest.scala:8)
[info] Falsified after 0 successful property evaluations.
[info] Message: 0 was not greater than 1
[info] Location: (SummaryTest.scala:10)
[info] Occurred when passed generated values (
[info] ""
[info] )
[info] Init Seed: 0
【讨论】: