Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Automate Grails App Code Coverage Reporting with TeamCity - Part 3

DZone's Guide to

Automate Grails App Code Coverage Reporting with TeamCity - Part 3

· Java Zone
Free Resource

The single app analytics solutions to take your web and mobile apps to the next level.  Try today!  Brought to you in partnership with CA Technologies

We'll finish the short series on continuous integration of Grails applications with TeamCity today. Last time we talked about enabling unit and integration tests, this time we'll collect code coverage reports with Cobertura.

I got the initial inspiration from Etienne Studer's blog, who's described how to enable Cobertura for Java projects in TeamCity. For Grails applications not much really needs to be done differently.

Install code coverage plugin

First, you need to install the code coverage plugin into your Grails application, as described on the Test code coverage plugin page. This would allow you to run grails test test-app-cobertura command to locally run your tests and collect code coverage data using Cobertura at the same time.

Modify build.xml

Second, you need to add an Ant target to the build.xml file, which would invoke the grails test test-app-cobertura command and zip both the test report and the code coverage report for on-line browsing.

	<!-- =================================
target: cobertura-covered test
================================= -->
<target name="test-cobertura"
description="--> Run a Grails applications unit and integration tests with code coverage">
<exec executable="${grails}" failonerror="false" resultproperty="resultCode">
<arg value="test"/>
<arg value="test-app-cobertura"/>
</exec>
<zip basedir="test/reports/html" destfile="test/reports/testReport.zip"/>

<fail status="1" message="Some tests failed">
<condition>
<equals arg1="${resultCode}" arg2="1"/>
</condition>
</fail>

<zip basedir="test/reports/cobertura" destfile="test/reports/cobertura.zip"/>
</target>

Modify artifact mapping

The third step is to update the .BuildServer/config/main-config.xml mapping file to indicate that the code coverage zipped report should be available for on-line browsing. After adding cobertura the file now contains three extra lines with our custom mappings.

  <report-tab title="Unit Tests" basePath="unitTestReport.zip" />
<report-tab title="Grails Tests" basePath="testReport.zip" />
<report-tab title="Cobertura" basePath="cobertura.zip" />

Configure Ant runner

The last step is to configure the Ant runner for our build to execute the appropriate Ant target. It is similar to what we did last time for unit and integration tests.

You need to specify the build file, the target to invoke and paths to both the test report and the code coverage report zip files so that TeamCity saves them for browsing. Thanks to the mapping in .BuildServer/config/main-config.xml file TeamCity knows that the files contain reports and will offer them for on-line viewing.

No you can quickly navigate the code coverage reports and view them on-line.

 

 

Summary

This is the end of the series. Now you should be able to use TeamCity to continuously build your Grails projects, run all tests, get notification whenever any of the tests fails and browse through test and code coverage reports on-line.

CA App Experience Analytics, a whole new level of visibility. Learn more. Brought to you in partnership with CA Technologies.

Topics:

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}