Search code examples
gradlespockgeb

When using gradle with Geb, how is the order of execution determined for my specifications?


I have a set of specifications that need to be ran in an exact order for the last specification to be relevant. These specifications need to be dependent on each other because of a complex use case involving server resiliency (1 server going down, another coming up to continue).

In order to make this happen, I've named my specifications alphanumerically as "T101_Something1", "T102_Something2", ... "T109_LastSpec".

However, when running my tests with the command "gradle firefoxTest", the tests are ran in a non alphanumeric order causing the last specification to be irrelevant and always fail.

How is the execution order of Spock specifications determined when using gradle with the Geb framework?


Solution

  • We had to create a custom JUnit test runner and run it as:

    gradlew -DfirefoxTest.single=CustomJUnitSpecRunner firefoxTest

    The CustomJUnitSpecRunner.groovy file:

    package spec
    
    import org.junit.runner.RunWith
    import org.junit.runners.Suite
    import spec.Spec1
    import spec.Spec2
    import spec.Spec3
    
    @RunWith(Suite.class)
    @Suite.SuiteClasses([Spec1.class, Spec2.class, Spec3.class])
    class CustomJUnitSpecRunner {
    }
    

    This allows us to guarantee the execution order of our Spock Specifications every time they are ran.