【问题标题】:Property test value is ignored by scalatestscalatest 忽略属性测试值
【发布时间】:2018-06-22 05:55:25
【问题描述】:

这个让我发疯。以下属性测试以 scalatest 方式通过(使用“sbt test”目标)。

import org.scalatest.FlatSpec
import org.scalatest.prop.PropertyChecks

class FigaroCheckSpec extends FlatSpec with PropertyChecks {
  "this property" should "fail" in { forAll { (p :Int) => false } }
}

为什么?我尝试了 FlatSpec 和 FreeSpec。当我直接将 Checkers 与 scalacheck API 一起使用时,它也可以工作(即失败)。

【问题讨论】:

    标签: scala scalatest scalacheck


    【解决方案1】:

    你没有检查/断言,试试这个:

    "this property" should "fail" in { forAll { (p :Int) => assert(false) } }
    

    【讨论】:

    • 哦。我懂了。知道非常有用。文档对于 scalacheck 和 scalatest API 的区别有点混乱。他们几乎给人的印象是,这只是使用不同的 forAll。谢谢! assert 在forall中显得过分了,但我想,如果我使用匹配器,它看起来会很合理。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-04
    • 2014-10-23
    相关资源
    最近更新 更多