Java Test Coverage Tool----Cobertura,eclemma

Source: Internet
Author: User


Cobertura is a code coverage measurement tool integrated with JUnit

It 's free, open source.

It can be integrated with Ant and Maven, or it can be called from the command line

can generate reports in HTML or XML format

HTML results can be sorted according to different criteria

Percentage of code lines and code branches that are covered for each class, package, and overall project calculation


Eclipse Plugin Address: http://ecobertura.johoop.de/update/ (requires Eclipse 3.5+)


Using Ant to perform Cobertura

Operation Steps:

1. Add the core dependency jar package---

2. Add a task definition to the Build.xml file. The following top-level taskdef element restricts the Cobertura.jar file to the current working directory:

<taskdef classpath= "Cobertura.jar" resource= "Tasks.properties"/>
3. The class being measured must appear in the Classpath before the original class appears in the Classpath, and the Cobertura JAR file needs to be added to the classpath:
<target name= "cover-test" depends= "instrument" > <mkdir dir= "${testreportdir}"/> <junit dir= "./" Failureproperty= "Test.failure" printsummary= "yes" fork= "true" haltonerror= "true" > <!--normally you can         The Create this task is copying your existing JUnit target, changing its name, and adding these next, lines. You could need to a change of the locations to point to wherever you put the Cobertura.jar file and the instrument Ed classes. --<classpath location= "Cobertura.jar"/> <classpath location= "target/instrumented-classes"/> < classpath> <fileset dir= "${libdir}" > <include name= "*.jar"/> </fileset> <pa Thelement path= "${testclassesdir}"/> <pathelement path= "${classesdir}"/> </classpath> &LT;BATC        Htest todir= "${testreportdir}" > <fileset dir= "src/java/test" > <include name= "**/*test.java"/> <include NAMe= "Org/jaxen/javabean/*test.java"/> </fileset> </batchtest> </junit></target>> 

4. cobertura-report Task Generation test report HTML file:

<target name= "Coverage-report" depends= "Cover-test" > <cobertura-report srcdir= "src/java/main" destdir= " Cobertura "/></target>
5. srcdir property to specify where the original. Java source code is. The destdir Cobertura property specifies the name of the directory where the output HTML is placed.

Once you have added a similar task to your ANT compilation file, you can generate an overwrite report by typing the following command:

% ant instrument% ant cover-test% ant coverage-report


There is also a simpler tool on the Java Test Coverage tool :eclemma(recommended) , which I am currently using Eclemma, which can be easily integrated with Eclipse, can then run directly, showing code coverage with the address: http://www.eclemma.org/

We can search and download the installation directly in Eclipse's marketplace

Here I do not introduce too much, interested students can try their own.


Don't overestimate your strength in the collective, because when you choose to leave, you will find that even without you, the sun rises as usual!

Java Test Coverage Tool----Cobertura,eclemma

Related Article

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.