By default, the ordering of Spec classes is not defined. This means they are essentially random, in whatever order the discovery mechanism finds them.
This is often sufficient, but if we need control over the execution order of specs, we can do this by specifying the order in project config.
There are several options.
Lexicographic- Specs are ordered lexicographically.
Random- Specs are explicitly executed in a random order.
Annotated- Specs are ordered using the
@Orderannotation added at the class level, with lowest values executed first. Any specs without such an annotation are considered "last". This option only works on the JVM. Any ties will be broken arbitrarily.
Given the following specs annoated with @Order.
BarTest will be executed first, as it has the lowest order value.
FarTest will be executed next, as they have the next lowest order values, although their values are both 1 so the order between them is undefined. Finally,
BooTest will execute last, as it has no annotation.