Tip : Exclude trivial getters/setters/constructors from cobertura code coverage report

When it comes to quality first thing we say is “90%” code coverage. To me whats important is 100% coverage for code that is doing some non-trivial work. For java code you can avoid trivial code and classes easily . Just use following configuration.

<plugin>
		<groupId>org.codehaus.mojo</groupId>
		<artifactId>cobertura-maven-plugin</artifactId>
		<version>2.6</version>
		<configuration>
			<formats>
				<format>xml</format>
				<format>html</format>
			</formats>
			<instrumentation>
				<ignoreTrivial>true</ignoreTrivial>
				<excludes>
					<exclude>**/some/trivial/classes/**</exclude>
				</excludes>
			</instrumentation>
		</configuration>
		<executions>
			<execution>
				<goals>
					<goal>clean</goal>
					<goal>check</goal>
				</goals>
			</execution>
		</executions>
	</plugin>
Advertisements

3 thoughts on “Tip : Exclude trivial getters/setters/constructors from cobertura code coverage report

  1. Hi Ganesh,

    I have multiple package structure’s,
    1) com.abc.def.classes
    2) com.qwe.cde.classes

    I would like all the classes to be excluded from com.abc.def.classes package in the report. I have tried to add ‘com/abc/**’ and ‘com/abc/**/*.class’ separately in the exclude tag shown above. For some reason it still does get included in the code coverage report. I have this configuration under the build directory. Following is an example,

    org.codehaus.mojo
    cobertura-maven-plugin
    2.4


    com/abc/**

    package

    cobertura


    html
    xml

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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