Is there any way to see the JaCoCo results on bytecode, so that you know which actual bytecode instructions the ones are that are not yet covered. The default report is somewhat unhelpful as it only says 1 of 9 branches missed.
Asked
Active
Viewed 719 times
2
-
But jacoco provides detailed html report. What you are mentioning is the summary report click on the class name and it will take to actual source html and highlight the lines of code not yet covered. – Himanshu Bhardwaj Sep 22 '16 at 23:28
-
@HimanshuBhardwaj no, I do not. I talk about the detail report. But if you have an if that checks three conditions and the detail report just says `1 of 6` branches missed, it does not help in any way. Seeing annotated bytecode would. – Vampire Sep 23 '16 at 10:37
-
What you actually want is to see the coverage of individual executable segments in a line containing one or more conditionals. Tools like JaCoCo don't have this feature, and will probably never have (based on their planned roadmaps). The JMockit coverage tool, however, does show individual segment coverage (though it's not perfect in all cases yet). – Rogério Sep 26 '16 at 20:10
-
Ah, ok, I'll have a look at it eventually Rogério, thanks – Vampire Sep 28 '16 at 07:59
1 Answers
0
JaCoCo maps coverage to source lines. That may be not enough if your code is very complicated and you have a lot of branches per line (if one-liners, overuse of '?' operator).
If you really want per-bytecode coverage you may want to preprocess your sources somehow. First idea that came to my mind was "disassemble java with javap and then reassemble", but few years ago it wasn't possible and quick googling for "java assembler" didn't yield any valuable results now.
If your "lines" aren't easily covered by tests, maybe it's a sign that you need to rewrite that piece of code?
-
I don't think a `while (conditionA && conditionB && conditionC)` is too complex code. But the info `1 of 6 branches missed` is simply not enough. – Vampire Sep 23 '16 at 10:40
-
Okay, maybe you have dead code in those conditions? A stronger checks before? Example: while (it.hasNext() && it != null) {...} Findbugs and Sonar should be able to find those. – okutane Sep 23 '16 at 10:45
-
No, I had not. I already found the missing code-path and was able to increase the coverage to 100% branch coverage. But it is tedious to introduce the logging and then interpret it correctly. It would be much easier if I could look at it in bytecode. Are you sure the mapping of coverage to lines is already done at recording time and not during analysis of the `exec` file? Because if the information is in the `exec` file, some tool should be able to transform it into a report. – Vampire Sep 23 '16 at 11:11