4.1. Understanding Spock from the ground up
At the lowest level, a Spock test method is highly characterized by its individual blocks. This term is used for the code labels inside a test method. You’ve already seen the given-when-then blocks multiple times in the previous chapters, as shown in the following listing.
Listing 4.1. Spock blocks inside a test method
Apart from the given-when-then blocks, Spock offers several other blocks that express different test semantics. The full list is shown in table 4.1.
Table 4.1. Available Spock blocks
Spock block |
Description |
Expected usage |
---|---|---|
given: | Creates initial conditions | 85% |
setup: ... |
Get Java Testing with Spock now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.