Running Clover on Bamboo – Code Coverage

Code coverage is the percentage of your source code that is covered by the automated tests. It determines which part of your code has been covered/executed in the test and which part are not covered. The importance of code coverage is that it answers the following interesting questions with regard to our project.

  1. How well the code is tested by the unit tests?
  2. Is the amount of tests enough? Or do we need more?
  3. How to maintain the quality of testing throughout the life-cycle of the project?

When trying to answer these questions, we will find that, having a single code coverage for the whole project which has multiple modules will not be enough as it will hide large gaps. So the code coverage should run for each module of your system.

Clover is such a code coverage tool from atlassian. It can be integrated into your IDE or in to your Continuous Integration system. As i mentioned in my previous post, I was trying out Bamboo (v3.3.4), which is a CI tool from atlassian, I thought integration of Clover with Bamboo would be easy. Clover has support for both Maven and Ant build tools.

You can integrate clover with bamboo in two ways. Automatic and Manual are the two ways. First of wall you have to enable the clover plugin under plugins section in the Administration page. You will also have to provide a licensee for clover. Luckily alassian allows to try their products using an evaluation licence. You will have to register with their site to get those evaluation licenses.

Automatic integration will work seamlessly for your build. The manual configuration is used when you want to specify different path build or target directories where the reports for the clover will be generated so that clover can look up these directories to parse and present them to the user. To enable this, go to your plan and click on the configure drop down menu for your job(mostly its the Default job). Then click on the “Miscellaneous” tab. And hen tick “Use Clover to collect Code Coverage for this build” option. After checking this, you can find two options, they are

  1. Automatically integrate Clover into this build.
  2. Clover is already integrated into this build and a clover.xml file will be produced.

The first option is where the automatic clover integration happens, and clover assumes that the clover report will be generated in the default target directory. (ie: /target/clover/clover.xml). But some times the automatic integration doesn’t work as expected. I have experienced this, where the automatic integration failed with failing to run some test cases for the project.

Second option should be checked if you manually configured clover for your build. If your automatic configuration doesn’t work, then here is how to manually setup clover with bamboo.

First of all you have to include the clover plugin in your build system. For example if you are using maven then include the clover maven plugin in your project object (pom.xml) file or in your maven configuration file (settings.xml).

    • Setup your pom.xml by adding the following in build plugin group
    • You can run clover without editing the pom file by adding it in the “~/.m2/settings.xml” file.

After that you have to invoke the Clover from maven command, that is

mvn clover2:setup test clover2:aggregate clover2:clover

You have to note that invoking clover should be separate task in your job for a build. That is the above maven command should run as a separate task which doesn’t include any compilation or install goals(ie mvn clean install). Because clover doesn’t work if it is included with project build command.

After completing the clover task, you can find the generated reports at “Bamboo_Home/xmldata/build_dir/Project_dir/target/site/clover/”. The main document is clove.xml, is what the bamboo looks to create the dashboard like reporting in the bamboo interface.

You can check your clover reports in the Clover tab which can be found in the project build Job page.


About kishanthan

I’m currently working as a Software Engineer at WSO2, an open source software company. I hold an Engineering degree, majoring in Computer Science & Engineering field, from University of Moratuwa, Sri Lanka.
This entry was posted in How to, Java, Software and tagged , , , , , , , , , , , . Bookmark the permalink.

Leave a Reply

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

You are commenting using your 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 )

Google+ photo

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

Connecting to %s