2016-08-01 27 views
2

我想确保我的斯卡拉检查属性运行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 
> 

如何其实它传递给我的财产?

+0

我想你打电话给sbt?你能告诉我们你怎么称呼这个属性?也许尝试从REPL的'property.check'? – jopasserat

+0

我使用sbt,我将命令添加到OP –

+0

看起来像当我从控制台运行它时我只获得100个测试以及'scala> res1._2.check + OK,通过了100次测试.' –

回答

1

据我了解,你可以指定两个级别的测试参数,他们似乎没有沟通。

第一个选项是在物业内,你想要做的事:

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外壳或直接在课堂内。

现在,如果你想影响运行调用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") 
+0

这似乎不允许每个测试或每个属性的设置? – nafg

0

肯定有实现更简单的方法这比覆盖任何种类的全球测试配置:

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

看起来你正在使用ScalaTest? –

+0

嗨@ChrisStewart是的,这只是一个例子,DSL不是ScalaTest特定的,至少forAll方面。 – flavian

+0

这是如何与'Prop.forAll()'函数中给出的显式生成器一起工作的? –