Creator of the Apache Tapestry web application framework and the Apache HiveMind dependency injection container. Howard has been an active member of the Java community since 1997. He specializes in all things Tapestry, including on-site Tapestry training and mentoring, but has lately been spreading out into fun new areas including functional programming (with Clojure), and NodeJS. Howard is a DZone MVB and is not an employee of DZone and has posted 81 posts at DZone. You can read more from them at their website. View Full User Profile

An Example Of Why I Like Spock

04.06.2011
| 5699 views |
  • submit to reddit

Spock is really making writing tests fun, instead of a chore.

    @Unroll("toClass '#javaName' should be #expectedClass")
def "toClass tests"() {
expect:

PlasticInternalUtils.toClass(getClass().classLoader, javaName) == expectedClass

where:

javaName | expectedClass
"java.lang.String" | String.class
"java.lang.Integer[]" | Integer[].class
"java.lang.Long[][]" | Long[][].class
"void" | void.class
"int" | int.class
"int[]" | int[].class
"float[][]" | float[][].class
}

 

This combines lots of things I've seen before in TestNG, but nicer; just more readable ... and the @Unroll annotation (which guides Spock on how to report the test execution) is really handy, especially when things go wrong. It's just a slick overall package. 

From http://tapestryjava.blogspot.com/2011/04/example-of-why-i-like-spock.html

Published at DZone with permission of Howard Lewis Ship, author and DZone MVB.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)

Tags: