Check automated code coverage and report analysis with Jacoco

Source: Internet
Author: User

Background: Although Jacoco out also has a period of time, the article also has, but the article on the Internet is a new test project, run down, everywhere is the pit ... So let's study it myself, and at least be more detailed than them.

Environment:
Android Studio 2.1.1 + gradle 2.10

Build:
In fact, Gradle comes with the Jacoco plug-in, just need to introduce the good, open build.gradle, add plug-ins in the first line:

Apply plugin: ' Jacoco '

The person on the network is using jacoco-android, then please skip, because it may be because of the version replacement, at least not the plugin.
Then, declare the use of the Jacoco version, this version of how to come, directly to the official website to copy the latest on the Line (http://www.eclemma.org/jacoco/):

OK, the introduction of plug-ins, specify the version, and finally in the buildtypes tag inside the debug switch on the line:

testcoverageenabled true

OK, in fact, the environment this is built to complete.

Use
As we all know, with the command to start, in the previous study Androidjunitrunner Google has actually given us two commands:

Gradlew Test/connectedandroidtest

These two commands are to execute (unit) the test and generate a report, and then a similar command if you want to test code coverage:

Gradlew Createdebugcoveragereport

Then error:

Well, the tutorial is to run this command, dead or alive error, OK, only x wall to ask Google, and then found that this command is in the JACOCO framework itself, not the testers themselves defined, and then invoke the command:
Gradlew task view, only to find out this command if there is a channel packet, you need to bring the channel number, then execute:

Gradlew Createofficialdebugcoveragereport

Well, execution succeeds, so be careful here.
Finally, the report generated directory in the build folder, relatively easy to find, not much to say, the latter is intended to integrate into Jenkins.
PS: the need to perform automated force reporting and code coverage reporting, without knocking two lines of command, a straight line can be:

Gradlew Connectedcheck

But this will run the channel bag all over again, remember to check only the official bag to keep the line, otherwise it is time-consuming.
This can output two reports at a time.

Analysis
Well, the report has, how to analyze, and how to automate test coverage. Now let's talk about it.

Element:
Can click into to see where to cover, can be accurate to the method, you can see which method is not covered, and then check the code logic, supplementary use cases.

Missed Instructions:
This is code coverage, green means run, red means no.

Missed Branches:
Branch coverage, in fact, the personal understanding of the condition statement is not covered in other cases

Missed cxty:
Don't understand ...

Missed Lines && Missed Methods && Missed Classes:
The number of rows and methods covered and the class

OK, with a few parameters you can click on the element to find out where it is not covered and needs to be overwritten.

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.