jeudi 9 juillet 2015

Spock unit test, groovy leftshift assignment is throwing a SpockExecutionException: Data provider has no data

I'm writing a spock unit test and I get the following error thrown when I try to supply a data provider dynamically using groovy collect

SpockExecutionException: Data provider has no data

Here is the simplest case I can provide that throws the error:

import spock.lang.Shared
import spock.lang.Specification

class SampleTest extends Specification {

    @Shared
    def someArray

    void setup() {
        someArray = ['a','b','c']
    }

    def "ensure that 'Data provider has no data' is not thrown"() {

        expect:
        columnA == columnB

        where:
        [columnA, columnB] << someArray.collect { value -> [value, value] }
    }
}

The groovy code seems to work. Here's my test on the groovy console:

def someArray = ['a','b','c']
def test = someArray.collect { value -> [value, value] }
println test

[[a, a], [b, b], [c, c]]

What am I misunderstanding?

I'm using:

  • groovy version 2.2.1
  • spock version 0.7-groovy-2.0
  • junit version 4.12

Aucun commentaire:

Enregistrer un commentaire