【问题标题】:Scalatest GeneratorDrivenPropertyChecks init seedScalatest GeneratorDrivenPropertyChecks 初始化种子
【发布时间】:2020-02-07 19:06:45
【问题描述】:

我正在使用Scalatest 3.1.0-SNAP13,但找不到如何从此PR 中指定初始化种子选项。 我正在使用 SBT 运行测试,所以如果有办法在 build.sbt 中指定此选项将是理想的。

【问题讨论】:

    标签: scala scalatest property-based-testing


    【解决方案1】:

    -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")
    

    【讨论】:

      【解决方案2】:

      我设法让它工作:

      // 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
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-05-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-01-05
        • 2011-03-25
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多