ygu*_*ygu 6 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
myProperty.check
}
}
Run Code Online (Sandbox Code Playgroud)
但这似乎是错的,因为当我使用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.
Run Code Online (Sandbox Code Playgroud)
所以问题是:我的财产是伪造的,但测试通过了!?!有人看到我的代码出了什么问题吗?
谢谢...
编辑:我试图调用myProperty而不是myProperty.check,但这不是更好,因为这样,生成器似乎被忽略(只启动一个测试而不是一百个).
最终,我找到了一种 Scalatest 考虑的编写测试的方法。我使用了 Checkers Trait 而不是 PropertyChecks:
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)
}
}
Run Code Online (Sandbox Code Playgroud)
我不确定这是最好的编写方式,但我得到了我想要的。本地:
*** 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 Code Online (Sandbox Code Playgroud)
最后:
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 ***
Run Code Online (Sandbox Code Playgroud)
如果有人可以评估这个建议,我会很高兴^^
| 归档时间: |
|
| 查看次数: |
893 次 |
| 最近记录: |