而不是調用forAll
,使測試類從org.scalatest.prop.Checkers
延伸,然後在每個測試中,調用check
與屬性進行測試。在這種情況下,「屬性」可能意味着您創建的forAll
。
所以我要去猜測,目前你有一個測試類,看起來像:
class ExampleSuite extends AssertionsForJUnit {
val fractions = Table(
("n", "d"),
( 1, 2),
///...
)
forAll (fractions) { (n: Int, d: Int) => // ...
@Test def verifySomethingElse = ???
}
我相信你需要做的是從跳棋擴展和移動你的forAll
到測試。
class ExampleSuite extends AssertionsForJUnit with org.scalatest.prop.Checkers {
@Test def verifyFractions = {
val fractions = Table(
("n", "d"),
( 1, 2),
///...
)
check(forAll (fractions) { (n: Int, d: Int) => ???)
}
@Test def verifySomethingElse = ???
}
你顯然是這裏的專家,所以我按照你的回答。 PropertyChecks是一種更簡單的方法來做'check(forAll ...)'的等價物嗎?我的回答是基於去年秋季在_Reactive Programming_課程中教授的方法。 –
主要區別是PropertyChecks使用ScalaTest斷言或匹配表達式,而Checkers使用ScalaCheck的傳統布爾表達式。如果你的屬性變大了,你需要在你的布爾表達式中插入ScalaCheck標籤,我認爲它們比斷言或匹配表達式更難讀。 –
@ Bill.Venners感謝您的解釋。我只是有機會使用PropertyChecks,並且必須說它比我一直使用的方法更清晰。 –