Jacoco Coverage Tools use

Source: Internet
Author: User

Jacoco Introduction

Jacoco is an open-source coverage tool. Jacoco can be embedded in ant, Maven, and provide eclemma Eclipse plug-ins, or you can use javaagent technology to monitor Java programs. Many third-party tools provide integration of JACOCO, such as Sonar, Jenkins, and so on.

Website address: http://www.eclemma.org/jacoco/

Java Counters

The Jacoco contains coverage counters of various scales, including instruction level (instructions,c0coverage), Branch (branches,c1coverage), cyclomatic complexity (cyclomaticcomplexity), Row (Lines ), Method (Non-abstract methods), Class (classes).

As shown, the green branches are covered in full , the yellow ones are partially covered , and the branches marked red are not executed .

Supported Integration tools

The Jacoco team provides support for some of the following integration tools:

Java API

Http://www.eclemma.org/jacoco/trunk/doc/api/index.html

Command Line

Http://www.eclemma.org/jacoco/trunk/doc/agent.html

Apache Ant

Http://www.eclemma.org/jacoco/trunk/doc/ant.html

Apache Maven

Http://www.eclemma.org/jacoco/trunk/doc/maven.html

Eclipse Ecldmma Plugin

http://www.eclemma.org/

Here's how to use the Ant tool, which will be done using a web-engineering example.

Apache Ant's Use Web Drawing

Executing the ant file Task:all-report

The report directory is generated after the ant file is executed:

Test report

You can run the command separately: Anttest-report generate test reports;

After execution, a test report is generated in build/report/html, where index.html is shown below. Under

Click: Enter:

Show the test class name, test method name, test status Success or fail, type, and execution time:

Test Case coverage

Commands can be executed separately: antcoverreport;

After execution, an overwrite report is generated under Build/report/coverage, where the index.html is opened as follows:

Click the package name layer one level click enter:

See the description above for a specific color definition .

Jacoco and Jenkins,sonar integrated with Jenkins to build a simple configuration

Figure is for reference only.

Jacoco and Jenkins Integration

First Jenkins installs the Jacoco plugin:

It is recommended to use Jenkins plug-in management for installation;

The corresponding Jenkins plugin see Https://wiki.jenkins-ci.org/display/JENKINS/JaCoCo+Plugin

Configuring the Jacoco Plugin

In "Addpost-build action", select ",":

Configure the following sections:

First section: Code coverage statistics file location;

The second part: the location of the classes file;

The third part: the location of the source file;

Fill in percentages as required;

Jacoco and Sonar integration

Create a new sonar-project.properties under the project and directory, as shown in the Web diagram.

Edit this file:

Performing sonar, Configuring the Jenkins Section 

Only the Sonar-runner can be executed, provided that Jenkins and Sonar-runner are integrated together;

Run Jenkins to perform the build task

See a similar result, indicating the end of the build.

At this point, you can view information such as code coverage through Jenkins.

Click to enter the test project:

Click on the "Codecoverage Trend" section to go to the detailed page:

Click into the detailed coverage file:

Sonarqube Show

Entry into the Sonarqube project: http://172.16.XXX.XXX9000/

Click Project Jacoco_test_project:

Go to the detailed page:

The left of the circle is the unit test coverage, the right is the unit test statistics;

Click to enter


Select View row coverage by drop-down box, no coverage line, branch coverage, no branch coverage;

Click to enter the test situation information page:

If there are errors, this section shows the error condition.

Jacoco Coverage Tools use

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.