Jacoco代码覆盖远程机器(Jacoco code coverage for remote machine)

编程入门 行业动态 更新时间:2024-10-18 02:32:30
Jacoco代码覆盖远程机器(Jacoco code coverage for remote machine)

我试图找到这个答案但很难在任何地方找到它。 我正在进行API测试,在进程中我需要从本地机器调用其余的API。 本地机器包含maven项目和调用相应rest API的框架。

我需要检查远程Rest API的代码覆盖率,并根据代码覆盖率形成报告。 请帮忙,怎么做?

注意:我发现此链接很有用,但没有详细说明该怎么做?

http://eclemma.org/jacoco/trunk/doc/agent.html

I tried to find this answer but hardly found it anywhere. I am doing the API testing, In process I need to call the rest API from my local machine. local machine contains the maven project and a framework to call respective rest API.

I need to check the code coverage of remote Rest API and form a report based on the code coverage. please help, how to do that?

Note: I found this link useful but it does not elaborate clearly on what to do?

http://eclemma.org/jacoco/trunk/doc/agent.html

最满意答案

你可能会做一些文件复制 - 取决于你运行测试的方式。

JaCoCo作为java代理运行。 因此,您通常会添加javaagent参数,如您链接到应用程序服务器的启动脚本的文档中所述。

-javaagent:[yourpath/]jacocoagent.jar=[option1]=[value1],[option2]=[value2]

所以它看起来像:

java -javaagent: -jar myjar.jar

使用tomcat,您可以将“-javaagent”部分添加到JAVA_OPTS或CATALINA_OPTS环境变量中。 应该与其他服务器类似。

这将创建jacoco * .exec文件。 您需要将它们复制回构建或CI服务器以显示其结果(例如,如果您使用声纳,则在运行声纳报告器之前​​需要这些文件)。 重要的是只包括您感兴趣的软件包。

您还可以为每个测试风格创建一个jacoco.exec文件(用于单元测试的jacoco.exec,用于集成测试的jacoco-it.exec,用于应用程序测试的jacoco-at.exec)。

而且我不会将覆盖率与性能测试结合起来 - 也就是说。

有关JBoss的 stackoverflow的一些示例

you will probably do a bit of file copying around - depending on the way you run the tests.

JaCoCo runs as a java agent. So you usually add the javaagent parameter as mentioned in the docs you linked to the start script of you application server.

-javaagent:[yourpath/]jacocoagent.jar=[option1]=[value1],[option2]=[value2]

so it would look like:

java -javaagent: -jar myjar.jar

Using tomcat you can add the "-javaagent" part into JAVA_OPTS or CATALINA_OPTS environment variables. Should be similar for other servers.

this will create the jacoco*.exec files. you need to copy those back to your build or CI server to show its results (for ex if you use sonar you need those files before running the sonar reporter). Its important to just include the packages you're interested in.

You can also create one jacoco.exec file per test flavour (jacoco.exec for unit tests, jacoco-it.exec for integration tests, jacoco-at.exec for application tests).

And I would not mix coverage with performance testing - just to mention that too.

There are some examples on stackoverflow for JBoss

更多推荐

本文发布于:2023-08-07 14:10:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1464554.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:机器   代码   Jacoco   code   machine

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!