Java Reference
In-Depth Information
the feature is intended to be used. Test cases are executable documentation, illustrating the
ways the author meant for you to use the feature.
16
Other than in book form, I mean. Writing books is both fun and easy. That's my story, and I'm sticking to it.
In the case of the Grails
BeanBuilder
, there's a test case called
grails.spring
.BeanBuilderTests
, which has a couple of very nice properties:
• It was originally authored by Graeme Rocher, the head of the Grails project and
17
Except for maybe Guillaume Laforge, Dierk Koenig, Paul King, Andres Almiray, or a few others. The
Groovy ecosystem is filled with wicked-smart developers.
• Thetestcasehasnearly30differenttestsinit,demonstratingeverythingyoumight
want to do with the class.
In this section I want to review some basic features of the
BeanBuilderTests
class.
In fact, I copied the class into the topic source code just to make sure everything worked. I
needed to remove a couple of tests that weren't relevant to running
BeanBuilder
inde-
pendently from Grails, but everything else tested successfully.
Before I continue, I should highlight this approach as a good general rule:
Test Cases
Downloading the source code of an open source project is useful even if you never look at
the implementation. The test cases alone are often more valuable than the actual document-
ation.
That advice might be more useful than anything else said in this topic.
The next listing shows the first test case in the
BeanBuilderTests
class.
Listing 7.27. The
BeanBuilderTests
class with its first test case
class BeanBuilderTests extends GroovyTestCase {