Java Reference
In-Depth Information
This isn't as big a deal from a developer point of view, but it's a huge issue for man-
agers. One of the reasons companies are reluctant to adopt new languages is that they
aren't sure how well they work in a production environment. Production code often
involves complex approval processes and performance assessments that can be ex-
tremely conservative.
If you would like to try Groovy in your system, testing is one easy way to do it.
Groovy has many testing capabilities built into the language, all of which work with
both Groovy and Java code. Best of all from a management point of view, at runtime
Groovy's just another JAR file.
This chapter reviews the Groovy APIs and libraries that make testing easier. First I'll
review how Java developers normally test applications, focusing on the JUnit library.
Then I'll show how Groovy enhances that process through its GroovyTestCase ex-
tension. Next I'll show how to test scripts written in Groovy, using subclasses of
GroovyTestCase . From there I'll discuss testing classes in isolation using mocks and
stubs. This involves the built-in mock and stub capabilities in Groovy, both through the
Expando class and through Groovy's MockFor and StubFor classes. Finally I'll show
you a glimpse of the future in the form of the powerful Spock framework, a pure Groovy
library that simplifies testing for both Java and Groovy projects.
Figure 6.1 is a guide to the technologies discussed in this chapter.
Search WWH ::




Custom Search