Kostis Kapelonis wrote this piece on importance of stubbing and mocking. When it comes to true unit tests, having a mocking framework such as Spock for Java is essential. Using a mocking framework ensures that your unit tests are fast, self-contained and deterministic.
A mocking framework can help you fake external systems, pre-program your classes with expected responses, and test hard-to-replicate error conditions.
Tutorial covers:
- Downloading and setting up Spock via Maven
- Some very brief theory on the goals of Spock
- Stubbing return data from methods
- Verifying interactions
- Capturing arguments
- Returning custom mocked responses
Also, explains how to use the external project of Spock reports. Excellent tutorial with example code included.
[Read More]