相反的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