Package spock.lang

Annotation Type Stepwise

  • @Target({TYPE,METHOD})
    public @interface Stepwise
    When applied to a spec, the annotation indicates that the spec's feature methods should be run sequentially in their declared order (even in the presence of a parallel spec runner), always starting from the first method. If a method fails, the remaining methods will be skipped. Feature methods declared in super- and subspecs are not affected.

    When applied to a feature method, the annotation analogically indicates that the feature's iterations should be run sequentially in their declared order. If an iteration fails, the remaining iterations will be skipped.

    @Stepwise is useful for specs with (logical) dependencies between methods. In particular, it helps to avoid consecutive errors after a method has failed, which makes it easier to understand what really went wrong. Analogically, it helps to avoid consecutive errors in subsequent iterations, when it is clear that the reason for one iteration failure usually also causes subsequent iterations to fail, such as the availability of an external resource in an integration test.

    Please try to use this annotation as infrequently as possible by refactoring to avoid dependencies between feature methods or iterations whenever possible. Otherwise, you will lose opportunities to get meaningful test results and good coverage.

    Please note:

    • Applying this annotation on a specification will activate ExecutionMode.SAME_THREAD for the whole spec, all of its feature methods and their iterations (if any). If it is applied to a data-driven feature method only, it will set the same flag only per annotated method.
    • @Stepwise can be applied to methods since Spock 2.2. Therefore, for backward compatibility applying the annotation on spec level will not automatically skip subsequent feature method iterations upon failure in a previous iteration. If you want that in addition to (or instead of) step-wise spec mode, you do have to annotate each individual feature method you wish to have that capability. This also conforms to the principle that if you want to skip tests under whatever conditions, you ought to document your intent explicitly.