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?
-
2Sonar does have per test coverage. See here for some hint. https://deors.wordpress.com/2014/07/04/individual-test-coverage-sonarqube-jacoco/ – AKS Aug 18 '15 at 15:02
-
Quite an informative link but is there a way to do it without Sonar? – Ahmad.Masood Aug 18 '15 at 22:01
-
1What Sonar does is to let you navigate from each individual test to the set of source files/lines the test has exercised. It does not provide it in the opposite direction, ie, from a line in tested code to the tests covering the line. JaCoCo itself doesn't have support for either. A coverage tool that provides the second feature is JMockit Coverage. – Rogério Aug 27 '15 at 21:40
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.

- 801
- 8
- 11
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.

- 4,209
- 2
- 27
- 36
-
3Jacoco does it, but not for integration tests. Only for unit tests. http://i.imgur.com/RUq7Xhn.png – mattalxndr Sep 30 '15 at 13:18
-
2@mattalxndr where do you see that? None of my jacoco reports show what you have sent in your image – alex Feb 26 '21 at 18:44