Over a million developers have joined DZone.

An Example Of Why I Like Spock

DZone's Guide to

An Example Of Why I Like Spock

· Java Zone
Free Resource

Learn how to troubleshoot and diagnose some of the most common performance issues in Java today. Brought to you in partnership with AppDynamics.

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

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

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


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

Understand the needs and benefits around implementing the right monitoring solution for a growing containerized market. Brought to you in partnership with AppDynamics.


Opinions expressed by DZone contributors are their own.


Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.


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

{{ parent.tldr }}

{{ parent.urlSource.name }}