Writing Tests with Spock

Learn about the Spock testing framework by creating a project that uses Spock to unit test Java code.

Introduction
Introduction
Introduction to the tutorial and links to further reading.
Label Flexibility
Label Flexibility
Spock supports a range of different test labels to help you write the most readable tests.
Data Pipes
Data Pipes
Often we want to test the same set of criteria with different sets of data. Data pipes is one mechanism to do this.
Data Tables
Data Tables
Data tables offer the same functionality as data pipes, but this syntax can sometimes be more readable for more complex sets of data.
Mocks
Mocks
We can provide "empty" objects, so we don't have to initialise the whole application to test a section, and we can use mocks to check our code is making the calls we expect.
Stubs
Stubs
Stub can provide simple interfaces, so we don't have to initialise the whole application to test a section.
Helper Methods
Helper Methods
Sometimes we need to move test code into a separate method. In this section, we look at some tips for this.
With
With
Sometimes we want to check more than one value on an object. We can use `with` to do this.
Verify All
Verify All
Test frameworks often stop the test at the first failure. Find out how to run all conditions to see which pass and which fail.
Specifications as Documentation
Specifications as Documentation
Spock tests don't just tell the computer how to test the application, they can help developers understand what the application is supposed to do.
Shortcuts used
Shortcuts used
Finally, let's summarise the shortcuts we've learnt and see links to further information.