Talk presented at Apache Con 2021 Groovy track.
Spock is a testing framework written in Groovy. I can confidently say that Spock is the best testing framework I ever used. The reason for this is the expressive specification language provided by the framework along with the productivity benefits offered by the Groovy language. Spock leverages the JUnit ecosystem and hence can co-exist with tests written in JUnit. In this presentation, we explore several features of Spock and understand how they add value to developers in terms of simplicity, readability, productivity, pragmatism.
We start by exploring the BDD style (given-when-then) structure of a Spock test and understand how it aids the developers to organise their thoughts and retain that clarity for the reader of the test as well. Then we move on to exploring the Spock way of writing assertions and understand the simplicity with which it provides expressive failure messages which aid in quick actionable feedback. Then we move on to realizing how Spock requires fewer tools and a smaller set of APIs to achieve functionalities such as mocking. In fact, Spock doesn't need an external library for mocking. In the final part of the presentation, we compare the approach of Spock in the areas of data-driven testing, ordering test cases, and co-existence with JUnit.