The following example code:
class MySpec extends spock.lang.Specification {
def "My test"(int b) {
given:
def a = 1
expect:
b > a
where:
b << 2..4
}
}
throws the following compilation error: "where-blocks may only contain parameterizations (e.g. 'salary << [1000, 5000, 9000]; salaryk = salary / 1000')"
but using a List instead of a Range:
where:
b << [2,3,4]
compiles and runs fine as expected.
Could I also specify a Range somehow?
Use
where:
b << (2..4)
The test can be optimized as below as well. Note no arguments to the test.
def "My test"() {
expect:
b > a
where:
a = 1
b << (2..4)
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With