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?
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 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.
Coverage : 84% Branch Coverage : 71% Missed : 9. Complexity : 24.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With