Spock Order Extension
This extension gives the opportunity to define the order between specs and its parent.
Like @Stepwise
it ensures a defined execution order and skipps all the following features if a feature fails.
Unlike @Stepwise
it effects the complete hierarchy and lets you modify the execution order.
-
you want to start your test with a feature of the child spec
-
you want to skip features of your base spec
Usage
Add dependency
<dependencies>
<dependency>
<groupId>net.oneandone.spock</groupId>
<artifactId>order-extension</artifactId>
<version>0.1</version>
<scope>test</scope>
</dependency>
</dependencies>
Annotate your spec with @Order
and define order with annotations: @After
and @Before
.
@Order(skip = 'base 5')
class OrderExtensionFullExampleTest extends Base {
@After("base 1")
def "child 1"() {
expect: true
}
def "child 2"() {
expect: true
}
@Before("base 2")
def "child 3"() {
expect: true
}
@After("base 3") @Before("base 4")
def "child 4"() {
expect: true
}
}
class Base extends Specification {
def "base 1"() {
expect: true
}
def "base 2"() {
expect: true
}
def "base 3"() {
expect: true
}
def "base 4"() {
expect: true
}
def "base 5"() {
expect: true
}
}
This gives the following execution order:
-
base 1
-
child 1
@After("base 1")
-
child 2 after step1 due to declaration order
-
child 3
@Before("base 2")
-
base 2
-
base 3 after base2 due to declaration order
-
child 4
@After("base 3") @Before("base 4")
-
base 4
-
base 5 (skipped)
@Order(skip = 'base 5')
Hints
-
Features which are not annotated are executed in declaration order
-
If
@After
does not point to the last base feature it must be followed by@Before
, so that it’s clear when to continue the execution with the base features.