Unit testing with Spock in Intellij Idea

Recently i have stared to learn Grails for my new project. For unit testing I use Spock. Unfortuantelly it turns out that test classes generated from Grails are using Junit by default.
Untill I find way to make Grails generate test with Spock template I have created file templates and live templates for Idea for generating test classes and test methods for Spock.

Spock Contoller Test File Template

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

import grails.plugin.spock.ExtendedControllerSpec

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


Spock Unit Test File Template

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

import grails.plugin.spock.UnitSpec

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


Live template for given-when-then test method

def "$NAME$"(){



Live template for expect-where test method

def "$NAME$"(){


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s