/ / Spock parametrization vs. Scala TableDrivenPropertyChecks - scala, scalatest

Parametryzacja Spocka kontra Scala TableDrivenPropertyChecks - scala, scalatest

Zawiera strukturę Spock @Unroll adnotacja, która powoduje, że każdy "przypadek" z testowania sparametryzowanego jest oddzielnym testem. Czy coś podobnego jest możliwe w ScalaTest?

Odpowiedzi:

0 dla odpowiedzi № 1

Najbliższym będzie sterowane właściwościami tabeli:

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
}
}

Istnieją inne techniki, takie jak "testy dzielenia się" i więcej testy oparte na właściwościach.