Reputation: 291
I'm writing a kind of integration test. I need to test if the tested environments are actually running.
pseudocode:
def "setup test"() {
expect:
service1.isRunning()
service2.isRunning()
}
def "test1"() {
expect:
service1.something() == 1
service2.something() == 2
}
def "test2"() {
// ...
}
Basically, I don't even want to see the results of "test1" and "test2" if the "setup test" fails (They will surely fail too!). How can I achieve this? I've tried @IgnoreIf
, but it seems to be a solution only for conditions that we can provide from outside of the test.
Upvotes: 0
Views: 385
Reputation: 42234
You can try to use @Stepwise
annotation (defined at the class level) to achieve guaranteed order, and skip remaining tests if failure happens. Of course, the side effect is that if test1
fails, test2
won't be triggered, but that's the simplest way to introduce sequential and conditional execution.
Indicates that a spec's feature methods should be run sequentially in their declared order (even in the presence of a parallel spec runner), always starting from the first method. If a method fails, the remaining methods will be skipped. Feature methods declared in super- and subspecs are not affected.
@Stepwise
is useful for specs with (logical) dependencies between methods. In particular, it helps to avoid consecutive errors after a method has failed, which makes it easier to understand what really went wrong.
Source: http://spockframework.org/spock/javadoc/1.0/spock/lang/Stepwise.html
Upvotes: 1