Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

An Example Of Why I Like Spock

DZone's Guide to

An Example Of Why I Like Spock

· Java Zone
Free Resource

Try Okta to add social login, MFA, and OpenID Connect support to your Java app in minutes. Create a free developer account today and never build auth again.

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

Build and launch faster with Okta’s user management API. Register today for the free forever developer edition!

Topics:

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}