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.

Peter Niederwieser
  • 121,412
  • 21
  • 324
  • 259
Tomas Romero
  • 8,418
  • 11
  • 50
  • 72

1 Answers1

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.

Aravind Yarram
  • 78,777
  • 46
  • 231
  • 327
  • 2
    And for Geb, use `Geb(Reporting)Spec` together with `@Stepwise`. – Peter Niederwieser Nov 27 '12 at 06:57
  • When extending from IntegrationSpec, @Stepwise works, but when extending GebReportingSpec it doesn't. Any idea why? – Tomas Romero Nov 28 '12 at 01:45
  • 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. – Tomas Romero Nov 28 '12 at 03:31
  • It's a know issue between @Stepwise and inheritance: https://groups.google.com/forum/?fromgroups=#!topic/spockframework/UqogYwH77bY. Also http://code.google.com/p/spock/issues/detail?id=183. In fact, issued by Pangea. – Tomas Romero Nov 28 '12 at 04:54