In Spock, test classes are called specifications. They extend the library class and may contain • fields (instance, static, and shared) • fixtures (fixture methods that set up and clean up the state) • features (feature methods) • helpers (helper methods) The code of feature methods is split into logical blocks using the
Gherkin style. The
given and
setup blocks (which provide the same functionality) are used for setting up the initial state. The
when blocks describe actions,
then — the verifications of the action results, so each
when/then pair encapsulates a test step. The
expect block mixes the functionality of the
when blocks. This simplifies the test code for simple cases. The state can be restored in the
cleanup block. The additional
and block has no own meaning and is used for finer splitting steps into substeps of the same nature. The
where and
filter blocks allow specifying input and expected data. The values may be defined using the table syntax or as value streams. It allows the implementation of data-driven tests, including automatic calculation of
Cartesian products. All blocks except
where and
filter may have labels working as comments and visible in test reports. == Test execution ==