gpt4 book ai didi

ScalaCheck 专门针对属性的最低成功测试

转载 作者:行者123 更新时间:2023-12-04 19:39:32 24 4
gpt4 key购买 nike

我试图确保我的 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
>

我如何实际将其传递给我的属性(property)?

最佳答案

据我了解,您可以在两个级别上指定测试参数,但它们似乎无法通信。

第一个选项在您尝试执行的属性内:

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,这不会有任何影响。在属性(property)上。
可以来自 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")

关于ScalaCheck 专门针对属性的最低成功测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38703461/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com