1
Spock框架包含@Unroll
註釋,其結果是將參數化測試中的每個「案例」顯示爲單獨的測試。 ScalaTest有可能類似嗎?Spock參數化與Scala TableDrivenPropertyChecks
Spock框架包含@Unroll
註釋,其結果是將參數化測試中的每個「案例」顯示爲單獨的測試。 ScalaTest有可能類似嗎?Spock參數化與Scala TableDrivenPropertyChecks
最接近的將是table-driven property checks:
import org.scalatest.prop.TableDrivenPropertyChecks._
val fractions =
Table(
("n", "d"), // First tuple defines column names
( 1, 2), // Subsequent tuples define the data
(-1, 2),
( 1, -2),
(-1, -2),
( 3, 1),
(-3, 1),
(-3, 0),
( 3, -1),
( 3, Integer.MIN_VALUE),
(Integer.MIN_VALUE, 3),
(-3, -1)
)
import org.scalatest.matchers.ShouldMatchers._
forAll (fractions) { (n: Int, d: Int) =>
whenever (d != 0 && d != Integer.MIN_VALUE
&& n != Integer.MIN_VALUE) {
val f = new Fraction(n, d)
if (n < 0 && d < 0 || n > 0 && d > 0)
f.numer should be > 0
else if (n != 0)
f.numer should be < 0
else
f.numer should be === 0
f.denom should be > 0
}
}
還有其他一些技術,如"sharing tests"和 更property-based testing。