Kengo's blog

Technical articles about original projects, JVM, Static Analysis and TypeScript.

JUnit with Groovy2 by Maven3

Groovy is a good language to code JUnit test cases. Groovy is easy to learn, short to code, and simple to read. Today I changed my pom.xml to use Groovy 2.0 with JUnit 4.11, so I will share my change for you.

how to edit your pom.xml

What you have to add is not only gmaven-plugin, but also gmaven.runtime property to specify version of Groovy. Of course you have to add a dependency on Groovy itself, you can use test scope so it does not affect your package.

Your Groovy script should be put into src/test/groovy. Do not forget to use 'Test' as suffix when name your classes, because surefire-plugin needs it.