1

使用scalacheck,可以这样定义一些属性

object MyProps extends Properties("MyProps") {
  property("myProp1") = forAll { (n:Int, m:Int) =>
    n+m == m+n
  }
  property("myProp2") = forAll { ... }
  property("myProp3") = forAll { ... }
}

我想只为一个属性覆盖默认的最小成功测试数(minSuccessfulTests),例如仅用于"myProp2".

有没有办法做到这一点?

4

1 回答 1

0

PropFromFun您可以尝试隐式转换为您自己的Prop实现,而不是:

class PropWithParameters(prop: Prop, params: Test.Parameters) extends Prop {
    def apply(prms: Gen.Parameters) = prop(prms)

    def check(): Unit = {
         // Call super.check with params.
    }

    def withParams(moreParams: Test.Parameters): PropWithParameters = {
        // return a new instance with params merged with moreParams.
    }
}

object PropWithParameters {
    implicit def convert(input: Prop): PropWithParameters = {
        // Initialize with empty params here.

        // I'm not sure if implicits get aligned easily 
        // in case of a subclass.
    }
}

然后您可以执行以下操作:

object MyProps extends Properties("MyProps") {
    property("myProp1") = forAll { (n:Int, m:Int) =>
        n+m == m+n
    }
    property("myProp2") = forAll { ... } withParams(customParams)
    property("myProp3") = forAll { ... }
}
于 2015-05-04T10:24:03.817 回答