3

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.

JACOCO_OPTS="-javaagent:/opt/itop/jacoco-agent.jar=destfile=/opt/itop/jacoco-
it.exec,output=file,append=true,jmx=true"

JAVA_OPTS="${JAVA_OPTS} ${JACOCO_OPTS}"

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?
2
  • 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
    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. Mar 8, 2023 at 16:23

3 Answers 3

0
  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
3
  • Each of the API is covered with positive and negative test cases. Still getting this 3% only 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.
    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? Nov 1, 2018 at 10:55
0

It seems like you have already taken the initial steps to set up Jacoco for code coverage analysis in your application. However, there are a few more things that you can do to get better code coverage results:

  1. Ensure that all the necessary classes and packages are included in the coverage analysis by configuring the "includes" and "excludes" options in the Jacoco agent configuration.

  2. Make sure that your test suite covers all the possible execution paths in your application by including edge cases and negative scenarios.

  3. Run your test suite multiple times to get a more accurate coverage result, as certain parts of the code may only get executed in specific circumstances.

  4. You can also consider using a tool like SonarQube to analyze your code coverage and identify areas of your code that need more attention.

In terms of the standard to follow for code coverage, there is no fixed number that can be considered as "good" coverage as it depends on the complexity and criticality of the application. However, as a general guideline, a code coverage of at least 80% is considered to be a good target for most applications.

0

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.