Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find which test covers which line jacoco

I'm running integration test on a huge code base. In coverage report I want to know which test covered a certain line in code. Is there anyway of doing it with jacoco?

like image 405
Ahmad.Masood Avatar asked Aug 17 '15 11:08

Ahmad.Masood


People also ask

How do I check my JaCoCo coverage?

To get code coverage reports in a Maven project, we first need to set up the JaCoCo Maven plugin for that project. By integrating the JaCoCo plugin, the results of the code coverage analysis can be reviewed as an HTML report. The current version of the JaCoCo-Maven plugin can be downloaded from the MVN Repository.

How do I check my test coverage?

How to Calculate Test Coverage. Calculating test coverage is actually fairly easy. You can simply take the number of lines that are covered by a test (any kind of test, across your whole testing strategy) and divide by the total number of lines in your application.

What is branches covered ratio in JaCoCo?

Coverage : 84% Branch Coverage : 71% Missed : 9. Complexity : 24.

How do I see code coverage in SonarQube?

SonarQube itself does not calculate coverage. To include coverage results in your analysis, you must set up a third-party coverage tool and configure SonarQube to import the results produced by that tool. Below, you'll find guidelines and resources, as well as language- and tool-specific analysis parameters.


2 Answers

Just in case someone still looking for a solution to this question. In my case, I have written a small demo using Jacoco to generate a coverage report containing covered line information for each test case. Based on this project structure, I then simply wrote a script to automatically run test cases one by one and collect each coverage report to get information that which lines are cover by each test. Note that, this solution is not the best solution (it is time-consuming when the number of test cases is large), but it just helps me get the covered line information of test cases with Jacoco. Please refer to https://github.com/chenliushan/JacocoExample for the demo.

like image 165
liushan CHEN Avatar answered Sep 21 '22 08:09

liushan CHEN


JaCoCo doesn't collect that information, so it can't report it.

Conceivably, you could run each test independently with JaCoCo and generate a coverage report everytime, that way each test shows the exact lines of code it tested. (then you have to wrap this with a custom aggregated report I suppose, where you can navigate from one test to the next).

I get that this might not be practical with a huge codebase and a large number of tests. Another limitation is that you don't get to "what are ALL the tests that exercised that line of code ?".

As @Rogério remarked, other tools might be able to provide that functionality.

like image 41
Patrice M. Avatar answered Sep 17 '22 08:09

Patrice M.