ScalaCheck属性的特定最小成功测试数

qgzx9mmu  于 2023-03-08  发布在  Scala
关注(0)|答案(3)|浏览(106)

我试图确保我的ScalaCheck属性运行500次,而不是默认的100次,但我在配置时遇到了麻烦。

class BlockSpec extends Properties("BlockSpec") with BitcoinSLogger {

  val myParams = Parameters.default.withMinSuccessfulTests(500)
  override def overrideParameters(p: Test.Parameters) = myParams

  property("Serialization symmetry") =
  Prop.forAll(BlockchainElementsGenerator.block) { block =>
    logger.warn("Hex:" + block.hex)
    Block(block.hex) == block
  }
}

然而,当我实际运行这个测试时,它只显示成功通过了100个测试
编辑:

$ sbt
[info] Loading project definition from /home/chris/dev/bitcoins-core/project
[info] Set current project to bitcoin-s-core (in build file:/home/chris/dev/bitcoins-core/)
> test-only *BlockSpec*
[info] + BlockSpec.Serialization symmetry: OK, passed 100 tests.
[info] Elapsed time: 1 min 59.775 sec 
[info] ScalaCheck
[info] Passed: Total 1, Failed 0, Errors 0, Passed 1
[info] ScalaTest
[info] Run completed in 2 minutes.
[info] Total number of tests run: 0
[info] Suites: completed 0, aborted 0
[info] Tests: succeeded 0, failed 0, canceled 0, ignored 0, pending 0
[info] No tests were executed.
[info] Passed: Total 1, Failed 0, Errors 0, Passed 1
[success] Total time: 123 s, completed Aug 1, 2016 11:36:17 AM
>

我该如何将这笔钱转移到我的酒店?

gab6jxml

gab6jxml1#

据我所知,您可以在两个级别上指定测试参数,但它们似乎无法进行通信。
第一个选项是在属性中,正如您尝试做的那样:

import org.scalacheck.Properties
import org.scalacheck.Test.{ TestCallback, Parameters }
import org.scalacheck.Prop.{ forAll, BooleanOperators }
import org.scalacheck.Test

class TestFoo extends Properties("BlockSpec") {

  override def overrideParameters(p: Parameters) = 
    p.withMinSuccessfulTests(1000000)

  property("Serialization symmetry") = forAll { n: Int =>
    (n > 0) ==> (math.abs(n) == n)
  }

}

只要你不对属性调用.check,这就不会有任何影响。可以从sbt shell调用,也可以直接在类中调用。
现在,如果您希望在调用sbt:test目标时影响测试运行的数量,那么您似乎必须使用选项build.sbt(取自here):

name := "scalacheck-demo"

scalaVersion := "2.11.5"

libraryDependencies += "org.scalacheck" %% "scalacheck" % "1.12.2" % "test"

testOptions in Test += Tests.Argument(TestFrameworks.ScalaCheck, "-maxSize", "5", "-minSuccessfulTests", "33", "-workers", "1", "-verbosity", "1")
bfrts1fy

bfrts1fy2#

相比覆盖任何类型的全局测试配置,肯定有一种更简单的方法可以实现这一点:

class SampleTest extends FlatSpec
  with Matchers with GeneratorDrivenPropertyChecks {

  it should "work for a basic scenario" in {
    // This will require 500 successful tests to succeed
    forAll(minSuccessful(500)) { (d: String) =>
      whenever (d.nonEmpty) {
        d.length shouldBe > 0
      }
    }
  }
}
8yparm6h

8yparm6h3#

我使用munit看起来有点不同。下面是对我有效的方法,

import munit.ScalaCheckSuite
import munit.FunSuite

class FoobarTest extends FunSuite with ScalaCheckSuite {
  property(
    "Foo does the bar"
  ) {
    forAll { (intValue: Int) =>
      assert(intValue == intValue)
    }
  }.check(_.withMinSuccessfulTests(5000))
}

相关问题