Java Reference
In-Depth Information
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 productiv-
ity improvements in the past 20 years. Automated tests, running as part of your build pro-
cess, 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) move-
ment. There are two other benefits of automated testing, however, that aren't nearly as pub-
licized:
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.
My own experience is that the better the developer, the more he or she cares about test-
ing. The best developers write complete tests, and these tests run all the time as part of
a continuous integration system. If a test breaks, the system notifies the project com-
mitters right away. As a result, the tests are excellent examples of how the developers
intend the system to be used.
Whenever you work with a major open source project, download the source. You may
or may not look at the details, but the tests are invaluable.
2 . Tests aren't part of production code.
Search WWH ::




Custom Search