Chapter 4. Writing unit tests with Spock

This chapter covers

  • Working with Spock blocks
  • Understanding the lifecycle of a test
  • Improving readability of Spock tests
  • Using reusable JUnit features

All the Spock tests you’ve seen so far have been presented to you as a finished unit test, with no explanation of how to reach that particular code structure. You’re probably eager to create your own Spock tests from scratch. In this chapter, you’ll see all the building blocks that compose a Spock test and how they fit together (various combinations are possible).

You’ll also learn about the lifecycle of a Spock test and how to interact with its various phases. Finally, you’ll see some tricks for handling lengthy Spock tests and making them more readable ...

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.