Skip to content

Groovy Unit Testing with Ant and Team City

Well the title has a lot of product names in it some which might not be familiar to all of you, so i’ll try to give short descriptions

  • Groovy: An agile programming language inspired by ruby that compiles to Java classes, works on the JVM and integrates with existing  Java libraries. A must use for agile development and  / or prototyping.
  • Ant: Apache’s build tool
  • Team City: A great continous integration server by Jetbrains.

Groovy has Junit integrated with in it distribution and has the ability to run Groovy classes that extend the GroovyTestCase class directly as unit tests without the need for creating a Test Suit. This is great but when you use this method on Team City (or anyother CI server i presume) you cannot see how many tests passed, and how many faile. So here’s the work around I use to get over this issue:

  • I create a target in my build.xml that compiles all the groovy source code and copies it to a test folder
  • I have another target that compiles all the unit test code and copies them to the same test folder
  • Then I have Ant’s Junit task batch test all off the code with the filter *Test.class. Using this filter is important because Junit will go around looking for Java files as default.

When you deploy this on Team City and use the ant build runner, TC will show you your test stats.

Here is an excerpt from the build.xml file

<target name="compile" depends="init">
<groovyc srcdir="." destdir="../sandbox" classpathref="classpath"/>
<groovyc srcdir="../tests" destdir="../sandbox" classpath="classpath"/>
</target>
<target name="test" depends="compile">
<junit fork="no" haltonfailure="yes" maxmemory="512">
<jvmarg value="-Xmx512m"/>
<classpath refid="classpath"/>
<formatter type="brief" usefile="false"/>
<batchtest>
<fileset dir="../sandbox" includes="**/*Test.class"/>
</batchtest>
</junit>
</target>

Post a Comment

Your email is never published nor shared. Required fields are marked *
*
*