Eclipse 在将scalacheck与Propspec和PropertyCheck一起使用时,如何获得正确报告测试结果的ScalateTest?

Eclipse 在将scalacheck与Propspec和PropertyCheck一起使用时,如何获得正确报告测试结果的ScalateTest?,eclipse,scala,scalatest,scalacheck,Eclipse,Scala,Scalatest,Scalacheck,我想使用scalacheck的基于属性的测试来测试我的scala程序。我写道: class MyProperties extends PropSpec with PropertyChecks { property("My property") { val myProperty: org.scalacheck.Prop = new MyProperty // some code I need to set myProperty myPrope

我想使用scalacheck的基于属性的测试来测试我的scala程序。我写道:

class MyProperties extends PropSpec with PropertyChecks {
    property("My property") {
        val myProperty: org.scalacheck.Prop = new MyProperty
        // some code I need to set myProperty
        myProperty.check
    }
}
但这似乎是错误的,因为当我使用ScalaTest运行这个类时,我在控制台中:

Run starting. Expected test count is: 1
MyProperties:

! Falsified after 51 passed tests.
> ARG_0: myGeneratedArgument
- My property
Run completed in 1 second, 623 milliseconds.
Total number of tests run: 1
Suites: completed 1, aborted 0
Tests: succeeded 1, failed 0, canceled 0, ignored 0, pending 0
All tests passed.
所以问题是:我的属性是伪造的,但测试通过了!?! 有人看到我的代码有什么问题吗

谢谢


编辑:我试图调用myProperty而不是myProperty.check,但这并不是更好,因为这样,生成器似乎被忽略了(只启动了一个测试,而不是100个)。

最终,我找到了一种编写测试的方法,Scalatest考虑了该方法。我使用了Checkers特性而不是Property检查:

class MyProperties extends PropSpec with Checkers {
    property("My property") {
        val myProperty: org.scalacheck.Prop = new MyProperty
        // some code I need to set myProperty
        Checkers.check(myProperty)
    }
}
我不确定这是不是最好的写作方式,但我得到了我想要的。本地:

*** FAILED ***
  GeneratorDrivenPropertyCheckFailedException was thrown during property evaluation.
   (MyProperties.scala:175)
    Falsified after 0 successful property evaluations.
    Location: (MyProperties.scala:175)
    Occurred when passed generated values (
      arg0 = myGeneratedArgument
    )
最后:

Run completed in 4 seconds, 514 milliseconds.
Total number of tests run: 1
Suites: completed 1, aborted 0
Tests: succeeded 0, failed 1, canceled 0, ignored 0, pending 0
*** 1 TESTS FAILED ***

如果有人能对这个命题进行评估,我会很高兴^^

从ScalaTest测试您需要使用Checker或PropertyChecks。如果您使用的是传统的ScalaCheck属性,并且看起来像这样,那么应该使用checker(正如您发现的那样)。我唯一要补充的是,你可以说check而不是Checkers。check:

class MyProperties extends PropSpec with Checkers {
    property("My property") {
        val myProperty: org.scalacheck.Prop = new MyProperty
        // some code I need to set myProperty
        check(myProperty)
    }
}
Checker的完整文档如下所示: