简体   繁体   English

如何使用邮递员测试获得代码覆盖率

[英]How to get code coverage using postman test

We have REST services created in RestEasy and running in wildfly server.我们在 RestEasy 中创建了 REST 服务并在 Wildfly 服务器中运行。 We are running Postman test cases to test the Rest URLs.我们正在运行 Postman 测试用例来测试 Rest URL。

Is there a way to get a code coverage of the services when we execute postman test suite?当我们执行邮递员测试套件时,有没有办法获得服务的代码覆盖率?

We use SonarQube to analyse the code coverage.我们使用 SonarQube 来分析代码覆盖率。

I think no, a similar question was asked here: Generate Sonar code coverage report from Postman tests我认为不,这里问了一个类似的问题: 从邮递员测试生成声纳代码覆盖率报告

The original poster commented further down:原始海报进一步评论道:

In fact, after a bit of googling, as a work-around we could use remote Jacoco agent hooked in the java application server.事实上,经过一些谷歌搜索后,作为一种解决方法,我们可以使用挂钩在 Java 应用程序服务器中的远程 Jacoco 代理。 We'll try to run jacoco maven goals before and after the tests execution in order to generate jacoco coverage report.我们将尝试在测试执行前后运行 jacoco maven 目标,以生成 jacoco 覆盖率报告。 See: link I'll update the post if we have some progress.请参阅:链接,如果我们有一些进展,我会更新帖子。

Also, newman seems to have aticket about it: https://github.com/postmanlabs/newman/issues/408此外,纽曼似乎对此有所了解: https : //github.com/postmanlabs/newman/issues/408

Though this might help虽然这可能会有所帮助

Karate is the answer to your problem, provided you are willing to switch to another testing framework.空手道是您问题的答案,前提是您愿意切换到另一个测试框架。

Here is the link to the demo-example which has code-coverage working: https://github.com/intuit/karate/tree/master/karate-demo#code-coverage-using-jacoco .这是具有代码覆盖工作的演示示例的链接: https : //github.com/intuit/karate/tree/master/karate-demo#code-coverage-using-jacoco Since Karate is a JVM implementation it is straightforward, and I recommend you keep Karate tests in the same Maven module (or equivalent) for the easiest option.因为 Karate 是一个 JVM 实现,所以它很简单,我建议您将 Karate 测试保存在同一个 Maven 模块(或等效模块)中,以获得最简单的选择。 Otherwise it is possible, but just harder - and you will need to fiddle with a Maven profile etc or do some instrumentation synchronization gymnastics.否则它是可能的,但只是更难 - 你将需要摆弄 Maven 配置文件等或做一些仪器同步体操。

I guess if you already have a lot of tests in Postman, the advice here may not be practical.我想如果您已经在 Postman 中进行了大量测试,那么这里的建议可能并不实用。 But I'm posting this answer for the benefit of others who will come across this question in the future.但是我发布这个答案是为了将来会遇到这个问题的其他人的利益。

If you are lucky, you may be able to quickly port your tests to Karate using the experimental converter built into the UI: https://github.com/intuit/karate/wiki/Karate-UI#postman-import如果幸运的话,您可以使用 UI 中内置的实验性转换器快速将测试移植到空手道: https : //github.com/intuit/karate/wiki/Karate-UI#postman-import

Perhaps you can contribute to making that feature prod-ready.也许您可以为该功能做好准备做出贡献。

There is nothing available that provides code coverage for postman tests.没有任何东西可以为邮递员测试提供代码覆盖率。

In the end we chose rest assured and started replacing all postman tests.最后我们选择了放心,开始替换所有邮递员测试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM