Jacoco:查找外部测试的代码覆盖率 [英] Jacoco: Find code coverage for external tests

查看:281
本文介绍了Jacoco:查找外部测试的代码覆盖率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近在eclipse中使用EclEmma插件在我的应用程序中查找JUnits的代码覆盖率并且效果很好。

I recently used EclEmma plugin in eclipse to find code coverage of JUnits in my application and it worked great.

在下一步中,我希望能够找到我们的应用程序从外部调用的端到端测试/功能测试的代码覆盖率(它们位于单独的服务器上)。

In the next step, I want to be able to find code coverage for end-to-end tests / functional tests which are called on our application from outside(they reside on a separate server).

基本上,我们打包我们的应用程序作为jar(我们使用maven)并将其部署在服务器上。我们可以在这个位置触发功能测试。

Basically, we package our application as a jar (we use maven) and deploy it on a server. And we can trigger the functional tests at this location.

在这种情况下,有没有办法找到代码覆盖率?

我对理解代码覆盖率工具的工作方式(原始语言)是它加载类并根据已被命中的代码部分生成报告。因此,根据这种理解,我不需要访问测试代码。我只需要以某种方式代码覆盖率工具插入到我的应用程序jar中,并且无论何时调用此jar中的任何代码,都将更新报告。 我的理解是否正确?

My understanding of how code coverage tool works (in raw language) is that it loads the classes and generates a report based on the part of code that has been hit. So as per this understanding, I don't need to have access to the test-code. I only need to somehow plug the code coverage tool into my application jar and whenever any code in this jar is called, report will be updated. Is my understanding correct?

注意:
如果可以使用其他工具,我可以使用其他代码覆盖率工具。

NOTE: I am open to use other code coverage tool if this is possible with other tools.

推荐答案

您可以在服务器上运行代码,由JaCoCo代理在运行时检测,通过将代理添加到Java命令线。例如,如果您的流程目前已启用:

You can run your code on a server, instrumented at runtime by the JaCoCo agent, by adding the agent to the Java command line. For example if your process is currently launched with:

java -jar myApp.jar

您可以将其更改为

java -jar myApp.jar -javaagent:/some/path/jacocoagent.jar

默认情况下,这将覆盖覆盖范围当VM终止时,数据到文件 jacoco.exec ,但您可以使用选项覆盖它,使您能够通过TCP / IP获取覆盖数据。请参阅 JaCoCo Agent文档

By default this will write coverage data to the file jacoco.exec when the VM terminates, but you can override this with options, enabling you to get coverage data over TCP/IP. See the JaCoCo Agent docs.

您可以使用以下方法将其格式化为报告(例如HTML):

You can format this into a report (e.g. HTML) using:

java -jar jacococli.jar report jacoco.exec [options]

请参阅 JaCoCo CLI docs for options。

See the JaCoCo CLI docs for options.

...或者你可以使用EclEmma来分析输出。

... or you can use EclEmma to analyse the output.

如果有正当理由不能使用代理,作为最后的手段,您可以将类文件静态转换为已检测的类文件,在 jacocococli 中使用 instrument 命令。有关此信息,请参阅 JaCoCo'Offline Instrumentation'文档

If there are genuine reasons you can't use the agent, as a last resort you can statically convert your class files into instrumented class files, using the instrument command in jacocococli. See the JaCoCo 'Offline Instrumentation' documentation for information about this.

直接调用代理并使用 jacococli.jar 是使用JaCoCo的最基本方法。由于您使用的是Maven,因此您可以使用JaCoCo Maven插件获得许多相同的效果。

Directly invoking the agent and using jacococli.jar are the most basic ways of using JaCoCo. Since you are using Maven, you can get many of the same effects using the JaCoCo Maven plugin.

这篇关于Jacoco:查找外部测试的代码覆盖率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆