I'm trying to write functional test with Spock and Geb. I want to use in one test method multiple blocks of when/then with where for each block. Is it possible? Or I should use one where for all the when/then?
Multiple when/then with where for each other
You will not be able to use where
per interaction, it would complain about the usage. You would end up with a single where
for multiple interactions. Follow this as a sample:
def test() {
given:
def c
def d
when:
c = a + b
then:
c == result
when:
d = e - f
then:
d == res
where:
a | b |result | e |f |res
1 | 2 | 3 | 7 |5 |2
}
If you have multiple interactions to test, then yes you can very well do that in one method. Follow docs for details. @baxxabit –
Sinatra
Thank you! One small question. In an example you use one where block for every when/then. If I define variable like 'name' in where, it will be available in every when block? –
Elsy
Please, answer on my second comment :) –
Elsy
I am not sure which example you are referring to. But yes from the sample mentioned in the answer above, you can refer a variable inside data grid of
where
block like 'name' in every when block. @baxxabit –
Sinatra © 2022 - 2024 — McMap. All rights reserved.
@Stepwise
. – Ayana