Java Reference
In-Depth Information
Next, the class adds an assertLength method. It has three overloads. In each, the first
argument is the expected length of the array. The second argument is an array of integers,
an array of characters, or an array of type Object . Here I'm using the method to check
that the number of positive integers returned is as expected.
The class also provides an assertArrayEquals method, which takes two Object ar-
rays as arguments. The docs say that this method checks that the arrays are equivalent and
contain the same elements. [ 4 ]
4 That sounds like it's from the Department of Redundancy Department, but it's not.
Another added method is assertContains . That method has two overloads, one for
characters and one for integers, so it's only useful in those cases.
Finally, the superclass also provides the shouldFail method, which takes either an ex-
ception type and a closure or just a closure. It expects an exception when the closure is run,
so it behaves much as the @Test annotation with an expected property.
The GroovyTestCase class has a few additional methods that don't appear here, like
assertScript , shouldFailWithCause , and the ever-popular notYetImple-
mented . See the GroovyDocs for details.
The interesting part is that this test can be run from the command line. The groovy com-
mand acts as a text-based JUnit runner for GroovyTestCase subclasses. The result
looks similar to this:
$ groovy -cp bin src/test/groovy/mjg/JavaImplGTCTest.groovy
.Jun 23, 2013 5:53:05 PM java_util_logging_Logger$info call
INFO: inside testGetPositives
...
Time: 0.179
OK (4 tests)
The Java interface and implementation classes are compiled and reside in the project's bin
directory, so they need to be added to the classpath when running the Groovy script.
 
Search WWH ::




Custom Search