I have a multi module application "Project A". This application is hosted in clustered app nodes using tomcat as web server. We are using Spring, Web Services as primary among many other technologies to build this.

For doing the API Automation i have another project "Project B" which test all the public API of "Project A" using rest-assured.

Both the "Project A" and "Project B" are distinctly different and hosted in different GIT location. We do the build and test using Jenkins.

Now my requirement is to get code coverage of "Project A" using "Project B".

What I have Done till now:

A. I have installed jacoco-agent.jar in each of my app node and put the "JACOCO-ARGS" in the web server start up script.



B. We usually keep one node on only while looking for code coverage.

What I am getting now:

I am getting the jacoco-it.exec file generated but with very less coverage. With all the API passing i am getting only 3% coverage at max. Where as by doing manual testing we are getting more than 50%.

What I am looking for:

  1. Is there any other step which I am missing here?
  2. How to get max code coverage for this set up?
  3. What is the standard I need to follow while looking for code coverage?
  • I also has exactly same requirement. Can u please explain me in detail what all jacoco configuration you have done in project A and in project B and also on servers.
    – shilpi
    Commented Feb 5, 2020 at 13:52
  • Did anyone able to resolve this ? I am facing same problem. I have RestAssured testcased for all the end points but not getting any coverage in my iacoco report. One possible suggestion I found is to run my application a d test in the same jvm, but not sure how is this possible when I will execute my test in the pipeline. Commented Mar 8, 2023 at 16:23

2 Answers 2

  1. Check if your API tests with rest-assured operate with all the possible parameters (not just end-points) that could run your API in all possible ways
  2. Do not ignore negative tests. In my experience we just missed 50% of coverage because of we didn't bring the system into exceptional states which prevented the code to run into corresponding exception handling areas
  • Each of the API is covered with positive and negative test cases. Still getting this 3% only Commented Oct 26, 2018 at 10:25
  • You should have the report that would not only show the percentage but also uncovered code sections. You should analyze them to understand what should be amended in your tests.
    – Alexey R.
    Commented Oct 26, 2018 at 10:34
  • that report says some of the code got covered. But when we perform manual task those uncovered part also covering. The problem here is through API we are doing the same operation which manual team is doing. My question is how jacoco is differentiating it? is UI touch is mandatory to have a code coverage (I dont think so though)? How the connection should be set for jacoco-agent in app server so that it will capture each and every action perform on the application code? Commented Nov 1, 2018 at 10:55

To get code coverage via external Rest Assured API automation using JaCoCo, you can follow these steps:

Configure JaCoCo: First, you need to configure JaCoCo in your project to enable code coverage collection. Add the JaCoCo plugin to your build system (such as Maven or Gradle) and configure it to generate coverage reports.

Instrument your Code: JaCoCo works by instrumenting your code to collect coverage data. Make sure that your code is properly instrumented by enabling the necessary JaCoCo settings in your build configuration.

Write Rest Assured API Tests: Develop your Rest Assured API automation tests to cover the desired endpoints and scenarios. Ensure that your tests exercise different parts of your codebase to capture the code coverage accurately.

Execute Test Suites: Run your Rest Assured API automation test suites as part of your build or test execution process. This will trigger the execution of your tests and generate coverage data.

Generate JaCoCo Reports: After running the tests, JaCoCo will generate coverage reports based on the collected data. Configure your build system to generate the necessary JaCoCo reports, such as HTML or XML reports.

Analyze the Coverage Reports: Review the generated JaCoCo coverage reports to understand the code coverage achieved by your Rest Assured API tests. The reports will provide insights into which parts of your code were covered and which parts were not.

Improve Test Coverage: Analyze the coverage reports and identify areas of your code that have low or no coverage. Use this information to enhance your Rest Assured API tests and increase the coverage by adding additional test cases or scenarios.

Continuous Integration: Integrate the code coverage process into your continuous integration (CI) pipeline. Configure your CI server to generate and publish JaCoCo reports automatically after each test execution. This ensures that code coverage is monitored consistently as part of your development process.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.