Code coverage for functional tests

I have a RESTful Java API. I am using REST Assured for my functional tests on each endpoint.
Is there a way to get code coverage for classes / methods used behind the scenes (controllers, services, DAOs / repositories, etc.) when REST Assured (or any similar tool) makes API calls? (I guess the API must be started by some kind of agent or something that tells what happens until it stops?).

+3


source to share


2 answers


I ended up using JaCoCo (Java agent and Maven plugin) with SonarQube



EDIT after Sikandar's comment:
In my case, this is a Spring Boot application, so when I run the jar file I add the option
-javaagent:/myapp/lib/jacoco.agent-0.7.9.jar=destfile=/myapp/coverage-reports/jacoco-at.exec


Reports are generated when the application is stopped. Then I configured SonarQube to use a file /myapp/coverage-reports/jacoco-at.exec

to parse it

0


source


You can also use a service like Sealights as this is a problem we are solving (I work there) - getting code coverage outside of it means that all your functional, selenium, integration, performance testing are reported into one dashboard.

Please note that the solution you used (JaCoCo) is ok, but it has disadvantages such as:

  • This is for Java only.
  • You need to collect coverage from multiple computers and combine it (assuming you have microservices or many servers) to get the final report.
  • Coverage is only available when the process goes down, so if you have very long tests, it may take you hours until you get your initial information.

  • You cannot see the coverage of your inner and outer code in one place.



Basically at Sealights, we solve all these problems, help you focus your tests on areas in code that has changed, provide status reports, show you how your team is doing, including tips on how to optimize your tests and some other cool features. ...

Last but not least, we currently support Java, NodeJS, browser based tests (like Selenium), .NET and Python.

Happy programming; -)

0


source







All Articles