Chapter 6. Testing Groovy and Java projects
This chapter covers
- Using GroovyTestCase and its subclasses
- Testing scripts as well as classes
- The MockFor and StubFor classes in the Groovy library
- The Spock testing framework
The rise of automated testing is one of the most significant software development productivity improvements in the past 20 years. Automated tests, running as part of your build process, are very easy to set up, catch problems right away, and give you the freedom to refactor your code without worrying that you’re breaking something unrelated.
Testing is the cornerstone of many of the “agile” development processes, from more modern techniques like SCRUM to Kanban back to the original Extreme Programming (XP) movement. There are two other benefits of automated testing, however, that aren’t nearly as publicized:
1. Tests are executable documentation.
Any major open source project is a communal effort by some of the best developers in the world, many of whom are working on their own time. They’re highly motivated to write code, not documentation. The result is that the documentation quality tends to be inferior to the code quality, if it’s even up to date in the first place.