Cobertura-maven-plugin the interface when generating unit test reports, exception classes, constant classes

Source: Internet
Author: User

When we generate unit test coverage reports for a project using Cobertura, we often have the following requirements:

Requirements Description:

Because a project has many interface definitions, constant definitions, exception class definitions, these classes do not require unit testing. And when we use Cobertura to generate test reports, if we do not exclude these classes, it will make the reported data is not very good-looking, because after all, there are some of the classes are included in the corresponding unit test. So we want to be able to automatically exclude these interfaces, constants, and exception classes when generating test reports with Cobertura-maven-plugin.

Workaround:

In fact, it is very simple, as long as the Cobertura-maven-plugin in the project Pom.xml in the <excludes> elements under the <instrumentation> elements of these interfaces, constants, It's OK to rule out exceptions. To this end, we must abide by some of the conventions:

A common exclusion definition is as follows:

<plugin> <groupId>org.codehaus.mojo</groupId> <artifactid>cobertura-m 
     
            Aven-plugin</artifactid> <version>2.5.1</version> <configuration> <instrumentation> <!--charles:excludes the package name which con Tains "Interfaces", "constants", "Exceptions"--> <!--so now, the UT test coverage s Hould is much better--> <excludes> <exc Lude>com/walmart/platform/io/interfaces/*.class</exclude> <exclude>co M/walmart/platform/io/constants/*.class</exclude> &LT;EXCULDE&GT;COM/WALMART/PL Atform/io/exception/*.class</exculde> </excludes> </inst 
     
 Rumentation>      </configuration> </plugin> 

So we've eliminated a number of paths in the <exclude> here, So let's just do it in the project. All the interface classes are placed in the package path at the beginning of the com.walmart.platform.io.interfaces, all the constant classes are placed in the package path at the beginning of the com.walmart.platform.io.constants, all the exception classes Placed in the package path at the beginning of the com.walmart.platform.io.exception.

When running MVN Cobertura:cobertura, generating test reports automatically excludes these 3 categories.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.