How to exclude testng(test code) from clover coverage report


            I want to exclude the test code from my coverage report. While building the code itself  I have restricted the instrumentation. But still the test code is comping in the application code and showing the coverage percentage as 0%. My coverage report is showing 25% with test code 0%. Is it correct coverage report percentage? My goal is skip the test coverage % from actual coverage report.

Also, I could see the test codes are not instrumented.


<target name="with.clover">
<mkdir dir="ins-clover" />
<mkdir dir="cloversrc" />
<copy todir="cloversrc">
<fileset dir="src">
<exclude name="x/y/automation/**"> </exclude>
<exclude name="x/y/**Test**"> </exclude>
<fileset dir="test">
<exclude name="x/y/x/**"></exclude>
<exclude name="x/y/z/**"> </exclude>
<clover-instr initString="${clover.db.dir}/master_coverage.db" srcdir="cloversrc" destdir="ins-clover">

1 answer

1 accepted

0 votes
Accepted answer

In general Clover shows 2 types of coverage:

  • for application code 
  • for test code, in theory the second one should oscillate around 100%, since during testing the application coverage made by all of your test cases, so all the code should be executed (I'm excluding here situation when you want to check coverage of some test types and so on) 

Clover detects your test code with test detection algorithm, which you can modify with using testsources settings or here. You can exclude test sources from instrumentation, but doing that you'll loose some of the metrics, e.g Per-Test Coverage. But if you still want to do that, then:

  • do you remove cloversrc directory between runs, if not then there might be some old data which causes your problems
  • do you clean master_coverage.db between runs? if not then old instrumentation information might be included in the database
  • why are you copying the test sources at all to cloversrc directory at all ?
  • what do you mean by:

    &lt;exclude name="x/y/**Test**"&gt; &lt;/exclude&gt;

    I'd rather expect something like this:

    &lt;exclude name="x/y/**/*Test*"&gt; &lt;/exclude&gt;
  • Remember that all fileset patterns are resolved from project root, so you may need to modify the patterns to include it:

    &lt;exclude name="**/x/y/**/*Test*"&gt; &lt;/exclude&gt;
  • did you verify that none of the test sources are copied to cloversrc


Suggest an answer

Log in or Sign up to answer
Community showcase
Published Wednesday in Jira Service Desk

What's new in Jira Service Desk Server: Introducing 4.0 & more - Feb 2019

Hello Atlassian Community!  I'm Teresa, the Product Marketing Manager   for Jira Service Desk Server at Atlassian. I'm excited to announce two exciting releases for Jira Service De...

85 views 0 0
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you