Spock is a test framework — some would even say language — built on top of
Groovy. It was developed by Peter Niederwieser, first released in 2009, and,
after a long genesis, version 1.0 was released in 2015. Version 1.1 followed in
2017, and that’s the version w
e’ll be using in this book.
Although Spock builds on top of JUnit’s test runner it’s quite different
syntactically. Spock enforces a behavior-driven development (BDD)-style
structure. Instead of using methods to apply assertions, Spock infers that simple
Boolean expressions in particular contexts behave as assertions. Instead of
integrating external libraries like JMock or Mockito, Spock has its own test
doubles with dedicated syntax for defining expectations and behavior (although
you can use something else if you want). Spock also has syntax for defining
parameterized tests that goes far beyond the capabilities of JUnit’s
Above all, Spock specifications are very readable and expressive. Groovy’s
brevity and lack of ceremony is harnessed to a syntax that makes tests read
very well as executable documentation.