Part 1. Foundations and brief tour of Spock

 

Spock is a test framework that uses the Groovy programming language. The first part of the book expands on this by making sure that we (you, the reader, and me, the author) are on the same page.

To make sure that we are on the same page in the most gradual way, I first define a testing framework (and why it’s needed) and introduce a subset of the Groovy syntax needed for writing Spock unit tests. I know that you’re eager to see Spock tests (and write your own), but some features of Spock will impress you only if you’ve first learned a bit about the goals of a test framework and the shortcomings of current test frameworks (for example, JUnit).

Don’t think, however, that this part of the book is theory only. Even at this early stage, this brief tour of Spock highlights includes full code listings and some out-of-the-ordinary examples.

Chapter 1 is a bird’s-eye view of Spock, explaining its position in the Java ecosystem, the roles it plays in the testing process, and a brief comparison with JUnit. Feel free to skip this chapter if you’re a seasoned Java developer and have already written a lot of JUnit tests.