19

I am using EclEmma to test the coverage of my scenario tests and use case tests on my project. I have a Base package which contains the most general classes and the use case tests. The coverage looks like this:

Code coverage in our project

What I want is to exclude the use case tests (e.g. BugReportTest) from the coverage calculation. But I do want the tests inside it to be considered. I know how to exclude the entire class from the coverage but if I do that, my coverage % drops because the actual tests that check which lines of my code are tested are forgotten. These use case tests do need to stay in the Base package because of privacy reasons.

Programmer1994
  • 955
  • 3
  • 13
  • 29

1 Answers1

17

For technical reasons it might be necessary to exclude certain classes from code coverage analysis. The following options configure the coverage agent to exclude certain classes from analysis. Except for performance optimization or technical corner cases these options are normally not required.

  1. Excludes: A list of class names that should be excluded from execution analysis. The list entries are separated by a colon (:) and may use wildcard characters (* and ?). (Default: empty)

  2. Exclude classloaders: A list of class loader names that should be excluded from execution analysis. The list entries are separated by a colon (:) and may use wildcard characters (* and ?). This option might be required in case of special frameworks that conflict with JaCoCo code instrumentation, in particular class loaders that do not have access to the Java runtime classes. (Default: sun.reflect.DelegatingClassLoader)

Warning: Use these options with caution! Invalid entries might break the code coverage launcher. Also do not use these options to define the scope of your analysis. Excluded classes will still show as not covered.

Resource Link:

  1. EclEmma Code Coverage Preferences

The following examples all specify the same set of inclusion/exclusion patterns:

  1. <filter includes="com.foo.*" excludes="com.foo.test.*, com.foo.*Test*" />
  2. <filter includes="com.foo.*" /> <filter excludes="com.foo.test.*, com.foo.*Test*" />
  3. <filter value="+com.foo.*, -com.foo.test.*, -com.foo.*Test*" />
    <filter excludes="com.foo.*Test*" file="myfilters.txt" />
    where myfilters.txt file contains these lines:

    -com.foo.test.* +com.foo.*

Resource Link:

  1. Coverage filters
  2. I am certain that all of my classes are built with -g(debug='true') and yet EMMA still complains about missing debug info!

Ignore code coverage for unit tests in EclEmma

Preferences->Java->Code Coverage and set the "Only path entries matching" option to src/main/java - seems to work nicely

Community
  • 1
  • 1
SkyWalker
  • 28,384
  • 14
  • 74
  • 132
  • 1
    Gave the bounty to early :p This doesn't work for me. The tests are in the same folder and therefore can't be excluded... If I exclude them by using excludes, the tests aren't ran, but I need them to run to have coverage in the other classes... – Programmer1994 May 09 '16 at 01:26
  • @CedricCornelis Actually I have provided the procedure for excluding. I also have provided some useful links. You can go through this. – SkyWalker May 09 '16 at 02:11
  • @SkyWalker In Excludes: section how we have to give the classname/package name , can you please give an example , i mean did the classname/package should be com.abc,SomeClass.java or com.abc/SomeClass.java – Monis Majeed Jan 10 '17 at 04:43