Unable to retrieve JaCoCo coverage from exec file via Java API

Unable to retrieve JaCoCo coverage from exec file via Java API



We have JaCoCo for coverage. Some tests spawn a new java process for which I add the jacocoagent arguments and I get the expected jacoco.exec. Each file has a different path.



i.e. -javaagent:path/jacoco.jar=destfile=path/to/output.exec


-javaagent:path/jacoco.jar=destfile=path/to/output.exec



I merge those and generate a report in which they correctly show as covered from those external processes.



Later I try to use the merged.exec using the Java API but I can't get coverage on those methods to perform some internal calculations.



In some cases I found that there might be multiple class coverage records for certain line (I assume depending on how many times that particular line was executed) so I use the following methods to get the best coverage out of those:


private List<IClassCoverage> getJacocoCoverageData(ExecutionDataStore
execDataStore,
String classFile) throws IOException

List<IClassCoverage> result = new ArrayList<>();
logger.debug("Processing coverage for class: " + classFile);
final CoverageBuilder coverageBuilder = new CoverageBuilder();
final Analyzer analyzer = new Analyzer(execDataStore, coverageBuilder);
File file = new File(this.workspaceRoot, classFile);
logger.debug("Analyzing coverage in: " + file);
if (file.exists())

try (FileInputStream fis = new FileInputStream(file))

analyzer.analyzeClass(fis, file.getAbsolutePath());

Iterator<IClassCoverage> it = coverageBuilder.getClasses().iterator();
while (it.hasNext())

result.add(it.next());


return result;


private IClassCoverage getBestCoverage(List<IClassCoverage> coverage,
int workingCopyLine)

IClassCoverage coverageData = null;
for (IClassCoverage cc : coverage)
temp.getStatus()
> coverageData.getLine(workingCopyLine).getStatus())

coverageData = cc;


return coverageData;



Somehow I only find not covered coverage data. Both the reports and the methods above look at the same merged.exec file.




1 Answer
1



This turned out to be something completely unrelated to the JaCoCo file. The code above worked fine.



Thanks for contributing an answer to Stack Overflow!



But avoid



To learn more, see our tips on writing great answers.



Required, but never shown



Required, but never shown




By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Edmonton

Crossroads (UK TV series)