• Home
  • About
  • Getting Started with Spock and Groovy

    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, and you’re always welcome to upvote at DZone.

    Here are some useful links to read for this webcast:

    • Spock Framework – http://code.google.com/p/spock/
    • IDEA File Templates – http://www.jetbrains.com/idea/webhelp/file-templates.html
    • IDEA Live Templates – http://www.jetbrains.com/idea/webhelp/live-templates.html

    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! 

    Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
    • Y!GG
    • Webnews
    • Digg
    • del.icio.us
    • DotNetKicks
    • Facebook
    • Google Bookmarks
    • Newsrider
    • Newstube
    • TwitThis
    • YahooBuzz

    1 Comment

    1. Boyko Todorov said,

      April 16, 2011 @ 2:17 am

      Hey Hamlet,
      I have only only heard of Spock, but your presentation has picked my interest.
      Thanks much, very nice screencast!

    RSS feed for comments on this post