相反的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 { ... }
}
那不是覆盖默认分钟的成功测试次数为我的原始示例中的每个*属性?我只想覆盖它的一个属性。 – apolune
它肯定会。我开始写一个不同的答案,但后来改成这样,认为这很简单。 – muhuk
这会更简单。问题是,我有一个测试在1000次中只有1次不确定。所以我想要增加特定测试运行的次数,而不是通过超过必要的运行所有其他测试来减慢测试套件的运行速度。我*可以*只是将这一个非确定性测试移到另一个测试套件中,但我想看看我是否不必这样做。最后,这个问题可能是以这种方式使用“属性”的限制... – apolune