Determine order of execution of Spock tests
Asked Answered
A

1

24

Is there a way to set the order in which tests are executed within an Spock Specification?

For example:

class MySpec extends IntegrationSpec {
    def 'test A'...

    def 'test B'...
}

I want 'test A' to be execute always before 'test B'

This is because I'm doing some functional tests with Geb and Spock and data is not rolled back between tests.

Alliteration answered 27/11, 2012 at 1:15 Comment(1)
Oops, seems it's not about Kobayashi Maru test from Star Trek.Rosaniline
D
45

You can use @Stepwise annotation on a spec and spock will run each of the test definitions of the Spec in the order they are specified. Look at this example.

Detachment answered 27/11, 2012 at 4:56 Comment(4)
And for Geb, use Geb(Reporting)Spec together with @Stepwise.Donegan
When extending from IntegrationSpec, @Stepwise works, but when extending GebReportingSpec it doesn't. Any idea why?Alliteration
In fact, it do work with GebReportingSpec. The problem I was having had something to do with my spec extending a base spec. My subSpec has a setup method and i think that that (added to the inheritance) could cause my problem.Alliteration
It's a know issue between @Stepwise and inheritance: groups.google.com/forum/?fromgroups=#!topic/spockframework/…. Also code.google.com/p/spock/issues/detail?id=183. In fact, issued by Pangea.Alliteration

© 2022 - 2024 — McMap. All rights reserved.