How to get code coverage using postman test

2020-02-28 02:25发布

问题:

We have REST services created in RestEasy and running in wildfly server. We are running Postman test cases to test the Rest URLs.

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.

回答1:

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. We'll try to run jacoco maven goals before and after the tests execution in order to generate jacoco coverage report. 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

Though this might help



回答2:

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. 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. Otherwise it is possible, but just harder - and you will need to fiddle with a Maven profile etc or do some instrumentation synchronization gymnastics.

I guess if you already have a lot of tests in Postman, the advice here may not be practical. 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

Perhaps you can contribute to making that feature prod-ready.



回答3:

There is nothing available that provides code coverage for postman tests.

In the end we chose rest assured and started replacing all postman tests.