java - Spock unit test, groovy leftshift assignment is throwing a SpockExecutionException: Data provider has no data -
i'm writing spock unit test , following error thrown when try supply data provider dynamically using groovy collect
spockexecutionexception: data provider has no data here simplest case can provide throws error:
import spock.lang.shared import spock.lang.specification class sampletest extends specification { @shared def somearray void setup() { somearray = ['a','b','c'] } def "ensure 'data provider has no data' not thrown"() { expect: columna == columnb where: [columna, columnb] << somearray.collect { value -> [value, value] } } } the groovy code seems work. here's test on groovy console:
def somearray = ['a','b','c'] def test = somearray.collect { value -> [value, value] } println test [[a, a], [b, b], [c, c]] what misunderstanding?
i'm using:
- groovy version 2.2.1
- spock version 0.7-groovy-2.0
- junit version 4.12
use setupspec() instead of setup() access @shared variable way want to, indicated in @shared documentation. alternatively, can initialize shared variable during it's declaration.
import spock.lang.* class sampletest extends specification { @shared somearray // similar using // @shared somearray = ['a','b','c'] // use above instead of setupspec() if required // setupspec() invoked before test case invoked void setupspec() { somearray = ['a','b','c'] } def "ensure 'data provider has no data' not thrown"() { expect: columna == columnb where: [columna, columnb] << somearray.collect { [it, it] } } }
Comments
Post a Comment