3 ms·
If possible, write tests in Groovy and use Spock Framework. My production code is a mix of Java and Scala, and I found Groovy to hit sweet spot for testing.
by wiradikusuma 10y ago
If possible, write tests in Groovy and use Spock Framework.
My production code is a mix of Java and Scala, and I found Groovy to hit sweet spot for testing.
- vorg 10y agoUsing the collections syntax and closures from Apache Groovy makes glue code, testing, and build scripts for the JVM easy to write, but the more recent features like those used in Spock are confusing. The Spock example in the post has the | operator overloaded so a function is called, a function name made up of 6 words separated by spaces (rather than using camelCase), and the label syntax triggering AST transformations to provide a new semantic context... class HelloSpockSpec extends spock.lang.Specification { def "length of Spock's and his friends' names"() { expect: name.size() == length where: name | length "Spock" | 5 "Kirk" | 4 "Scotty" | 6 } } Wouldn't this be more straightforward and readable, without needing to rely on any of the confusing post-Strachan features added to Apache Groovy?... def HelloSpockSpec () { //length of Spock's and his friends' names def f = {name, length -> name.size() == length} assert f("Spock", 5) assert f("Kirk", 4) assert f("Scotty", 6) }