views:

1923

answers:

1

Is there a way to exclude code from inclusion into Cobertura coverage reports? We have some methods that should not be include in the coverage report and therefore not drive down the coverage numbers.

I know that Clover has such a functionality, but I have not found anything similar for Cobertura.

+7  A: 

You can exclude classes from instrumentation. Then they should not appear on reports. See exclude statements below.

You can also ignore calls to some methods. See ignore statement below.

If you are using maven, see maven plugin manual.

    <configuration>
      <instrumentation>
        <ignores>
          <ignore>com.example.boringcode.*</ignore>
        </ignores>
        <excludes>
          <exclude>com/example/dullcode/**/*.class</exclude>
          <exclude>com/example/**/*Test.class</exclude>
        </excludes>
      </instrumentation>
    </configuration>

And for ant see this.

<cobertura-instrument todir="${instrumented.dir}">
  <ignore regex="org.apache.log4j.*" />
  <fileset dir="${classes.dir}">
    <include name="**/*.class" />
    <exclude name="**/*Test.class" />
  </fileset>
  <fileset dir="${jars.dir}">
    <include name="my-simple-plugin.jar" />
  </fileset>
</cobertura-instrument>
Juha Syrjälä
Thanks. Is there anything that can be added to the code to exclude a method? Would be easier than a long long list in ANT. Any annotation support?
ReneS
I made a very quick search to Cobertura docs, but I couldn't find anyting about Cobertura's annotations. So it seems you need to work on your unit-tests or package structure to make your exclude lists shorter ;)
Juha Syrjälä
Ok, that confirms, that I have not missed anything. Hope for a hidden feature... well, maybe we get one sooner or later. Thanks!
ReneS