Hamlet D'Arcy has been writing software for over a decade, and has spent considerable time coding in C++, Java, and Groovy. He's passionate about learning new languages and different ways to think about problems, and recently he's been discovering the joys of both F# and Scheme. He's an active member of the Groovy Users of Minnesota and the Object Technology User Group, is a committer on the Groovy project, and is a contributor on a few open source projects (including JConch and the IDEA Groovy Plugin). He blogs regularly at http://hamletdarcy.blogspot.com and can be found on Twitter as HamletDRC (http://twitter.com/hamletdrc). Hamlet is a DZone MVB and is not an employee of DZone and has posted 28 posts at DZone. You can read more from them at their website. View Full User Profile

Getting Started with Spock and Groovy

04.18.2011
| 8211 views |
  • submit to reddit

This screencast demonstrates how to create Spock testing specifications. It covers creating basic when/then blocks, given/when/then blocks, expect/where blocks, and data tables. It explains how to create Spock file templates and Spock Live Templates for IDEA.

If there are any playback issues then you might try watching it from the JetBrains.tv site.

Here are some useful links to read for this webcast:

To work with Spock, I use one file template and three live templates.

My file template creates a Spock Specification with the correct java package and javadoc:

idea file template

The text of the template is:

#if (${PACKAGE_NAME} != "")package ${PACKAGE_NAME};#end

import spock.lang.Specification

#parse("File Header.java")
class ${NAME} extends Specification {

}

My first Live Template is the when-then template:

when then

The text of the template is:

def "$NAME$"() {
when:
$END$

then:
true
}

 

The second template is the given/when/then template:

given when then template

The text of the template is:

def "$NAME$"() {
given:
$END$

when:
// TODO: add when

then:
true
}

The last template is the expect/where template:

The text of the template is:

def "$NAME$"() {
expect:
$END$

where:
// TODO add where block
}

I've made a lot of screencasts and blog posts over the years. If you like this, then there are many ways to see the other stuff I've done:

Phew, that's a lot of self-promotion :)

Thanks for watching, and leave a comment!

From http://hamletdarcy.blogspot.com/2011/04/getting-started-with-spock-and-groovy.html

Published at DZone with permission of Hamlet D'Arcy, 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:

Comments

Aymen Ben Hmida replied on Mon, 2011/04/18 - 3:29am

hi,

nice a article. Waiting for next!!!!

Aymen Ben Hmida replied on Mon, 2011/04/18 - 3:29am

hi,

nice article. Waiting for next!!!!

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.