mardi 2 février 2016

Same `where` clause for multiple tests

I know about data driven testing with the where clause in Spock. But how can I expand this to use one where for multiple tests?

For example, I have I set of tests I want to run against different versions of a library:

@Unroll
def "test1 #firstlibVersion, #secondLibVersion"() {...}

@Unroll
def "test2 #firstlibVersion, #secondLibVersion"() {...}
...

The where clause might look like this:

where:
[firstlibVersion, secondLibVersion] <<
    [['0.1', '0.2'], ['0.2', '0.4']].combinations()

I don't want to repeat this same where clause in every test. I could achieve that by reading environment variables in the tests and running the test suite multiple times with different env vars (test matrix style as CI services like travis support it).

But I would prefer to do that directly in the tests so I don't have to run the test suite multiple times. Does Spock support this somehow?

Aucun commentaire:

Enregistrer un commentaire