我如何获得每个请求的Jacoco覆盖报告。

huangapple go评论69阅读模式
英文:

How can I get Jacoco coverage Report per Request

问题

我正在使用 jacoco 代理通过运行以下命令生成我的 覆盖率报告,格式为 xml 文件:

java -jar <path>/sample_projects/beta/jacoco-code-coverage/jacoco-code-coverage-example/src/main/resources/lib/jacococli.jar report <path>/sample_projects/beta/jacoco-code-coverage/jacoco-code-coverage-example/target/jacoco-it.exec --classfiles <path>/sample_projects/beta/jacoco-code-coverage/jacoco-code-coverage-example/target/classes/com --sourcefiles src/main/java/ --xml <path>/sample_projects/beta/jacoco-code-coverage/jacoco-code-coverage-example/target/report.xml

这基本上会将数据写入 jacoco-it.exec 文件,并保存先前的覆盖率数据。
但我希望每次请求都进行覆盖率分析,有没有办法删除 jacoco 代理收集的先前数据?

英文:

I am using jacoco agent to generate my coverage reports in the form of xml files by running the command:

java -jar &lt;path&gt;/sample_projects/beta/jacoco-code-coverage/jacoco-code-coverage-example/src/main/resources/lib/jacococli.jar report &lt;path&gt;/sample_projects/beta/jacoco-code-coverage/jacoco-code-coverage-example/target/jacoco-it.exec --classfiles &lt;path&gt;/sample_projects/beta/jacoco-code-coverage/jacoco-code-coverage-example/target/classes/com --sourcefiles src/main/java/ --xml &lt;path&gt;/sample_projects/beta/jacoco-code-coverage/jacoco-code-coverage-example/target/report.xml

This basically writes to jacoco-it.exec file and it saves previous coverage data as well.
But I want coverage analysis per request made, is there any way I can erase previous data collected by jacoco agent.

答案1

得分: 2

所以基本上我已经找到解决方案,只需在请求完成后重置中间件中的执行转储,按照以下顺序进行操作,我就能够获得每个请求的覆盖分析。

ExecDumpClient execDumpClient = new ExecDumpClient();
execDumpClient.setReset(true);
execDumpClient.dump("localhost", 36320);
英文:

So basically I got the solution just reset the exec dump at my middleware after the request has been made in this order I am able to get the coverage analysis per request.

 ExecDumpClient execDumpClient = new ExecDumpClient();
        execDumpClient.setReset(true);
        execDumpClient.dump(&quot;localhost&quot;, 36320);

huangapple
  • 本文由 发表于 2023年2月14日 20:25:33
  • 转载请务必保留本文链接:https://go.coder-hub.com/75447804.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定