ScalaCheck特性的最小成功测试数

ScalaCheck特性的最小成功测试数,scala,scalacheck,Scala,Scalacheck,我试图确保ScalaCheck属性运行500次,而不是默认的100次。不过,我在配置时遇到了问题 class BlockSpec extends Properties("BlockSpec") with BitcoinSLogger { val myParams = Parameters.default.withMinSuccessfulTests(500) override def overrideParameters(p: Test.Parameters) = myParams

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

如何将其传递给我的属性?

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

第一个选项位于您尝试执行的属性中:

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

}
只要不调用
,这将不会产生任何影响。请检查属性上的
。
可以来自sbt shell,也可以直接在类中

现在,如果您想在调用
sbt:test
目标时影响运行的测试数量,那么您似乎必须使用选项
build.sbt
(取自):


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

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

我猜你是从sbt来的?你能告诉我们你怎么称呼这个地方吗?也许可以尝试使用
属性。从REPL检查
?我确实使用sbt,我会将命令添加到oplook中,就像从控制台运行命令时,我也只通过了100个测试
scala>res1.\u 2.check+OK,通过了100个测试。
关于
res1.\u 2.检查(\u.withMinSuccessfulTests(500))
,确实有效,但它并没有真正回答最初的问题——应该有某种方法将这些参数传递给类,并使用SBTLook运行它们,就像使用ScalaTest一样?Hi@Christewart是的,这只是一个示例,DSL不是特定于ScalaTest的,至少是forAll端。这如何与
Prop.forAll()
函数中给出的显式生成器一起工作?@ChrisStewart查看方法签名,我认为有一个可用的重载,它将生成器作为第一个参数,最小值作为下一个参数。我看不出有任何方法可以使用vanilla scalacheck sbt框架实现这一点。这似乎不允许每个测试或每个属性设置?
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
      }
    }
  }
}