Determine order of execution of Spock tests

12,371

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.

Share:
12,371
Tomas Romero
Author by

Tomas Romero

Updated on June 16, 2022

Comments

  • Tomas Romero
    Tomas Romero almost 2 years

    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
    Peter Niederwieser over 11 years
    And for Geb, use Geb(Reporting)Spec together with @Stepwise.
  • Tomas Romero
    Tomas Romero over 11 years
    When extending from IntegrationSpec, @Stepwise works, but when extending GebReportingSpec it doesn't. Any idea why?
  • Tomas Romero
    Tomas Romero over 11 years
    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
    Tomas Romero over 11 years
    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.