8.2. Writing unit tests with Groovy
Groovy’s premise for writing unit tests is a significantly lighter syntax for expressing your intent. Though Groovy still resembles Java, its lightness comes from making a lot of Java’s syntax optional.
For instance, in Groovy semicolons, parentheses, and the return keyword are optional and can be left out, as illustrated by the following listing.
Listing 8.2. Groovy’s syntax is like stripped down Java
void logAndReturn(String message) { def logMessage = "${new Date()} - ${message}" println logMessage logMessage }
The listing also illustrates a number of other ways in which Groovy reduces the amount of boilerplate programmers have to write. Because Groovy’s default visibility modifier is public, you can omit ...
Get Effective Unit Testing now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.