Reputation: 5921
I have the following parameters for the same test:
a | b | c
1 | 2 | 3
11 | 22 | 33
Spock provides the @Unroll
annotation for tests similar to this (with this set of parameters you can run to same tests with the vectors [1, 2, 3] and [11, 22, 33]).
However, I need to run the same test for all the possible permutations (e.g [1, 2, 3], [1, 2, 33], [11, 2, 33] and etc, all the 8 combinations). How can I achieve it?
Thanks for any thoughts!
Upvotes: 11
Views: 2227
Reputation: 66
To answer cellepo 's comment:
It is possible to have the expectation associated with a permutation by extracting the c
data pipe.
def "data driven cross-product"() {
expect:
Math.max(a, b) == c
where:
[a, b] << [[1, 11], [2, 12]].combinations()
c << [2, 11, 12, 12]
}
combinations
always returns the permutations in the same order:
[['a', 'b'],[1, 2, 3]].combinations() == [['a', 1], ['b', 1], ['a', 2], ['b', 2], ['a', 3], ['b', 3]]
It will be hard to write if it's a combination of many variables though.
Upvotes: 1
Reputation: 171144
You need
where:
[a, b, c] << [[1, 11], [2, 12], [3, 13]].combinations()
Upvotes: 28