Check junit coverage on AEM cloud | Community
Skip to main content
AEMLearner-1989
April 19, 2023
Solved

Check junit coverage on AEM cloud

  • April 19, 2023
  • 3 replies
  • 3574 views

Hi Team,

 

Is it possible to check Junit coverage report on cloud manager(file info).

 

In local, we have unit coverage almost around 80% but in cloud it showing 52%

 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by ShaileshBassi

Hi @aemlearner-1989 

The Junit coverage happens in the same way which @nitesh_kumar-1  mentioned.


Can you try out the jacoco plugin to measure the JUNIT Coverage by adding the entry in your pom.xml file.
In our case, there is a very minor difference coming with AEM Cloud report and Jacoco Report -> index.html

<plugin> <groupId>org.jacoco</groupId> <artifactId>jacoco-maven-plugin</artifactId> <version>0.8.7</version> <executions> <execution> <goals> <goal>prepare-agent</goal> </goals> </execution> <!-- attached to Maven test phase --> <execution> <id>report</id> <phase>test</phase> <goals> <goal>report</goal> </goals> </execution> </executions> </plugin>

 

Hope this helps.

Thanks

3 replies

nitesh_kumar-1
Adobe Employee
Adobe Employee
April 19, 2023

Hi @aemlearner-1989 ,

 

Not sure how are you checking coverage on your local, if it's IDE then you have to understand IDE calculates coverage in a different way.

 

On Cloud Manager it's calculated by a mix of unit test line coverage and condition coverage using the formula:

Coverage = (CT + CF + LC)/(2*B + EL)
CT = Conditions that have been evaluated as true at least once while running unit tests
CF = Conditions that have been evaluated as false at least once while running unit tests
LC = Covered lines = lines_to_cover - uncovered_lines
B = total number of conditions
EL = total number of executable lines (lines_to_cover)

 

More details here:- https://experienceleague.adobe.com/docs/experience-manager-cloud-service/content/implementing/using-cloud-manager/test-results/code-quality-testing.html?lang=en#ratings 

 

The recommendation would be to generate the code coverage result using the Jacoco plugin locally which is part of the standard archetype.

 

At the moment you can't see the coverage per file on CM, but the overview of the course is available along with logs. but if you use Jacoco locally it shouldn't matter because the AEM Cloud manager uses the same during the build as mentioned here:-

https://experienceleague.adobe.com/docs/experience-manager-cloud-manager/content/getting-started/project-creation/build-environment.html?lang=en#details 

 

Hope this helps!

 

Regards,

Nitesh

 

ShaileshBassi
Community Advisor
ShaileshBassiCommunity AdvisorAccepted solution
Community Advisor
April 19, 2023

Hi @aemlearner-1989 

The Junit coverage happens in the same way which @nitesh_kumar-1  mentioned.


Can you try out the jacoco plugin to measure the JUNIT Coverage by adding the entry in your pom.xml file.
In our case, there is a very minor difference coming with AEM Cloud report and Jacoco Report -> index.html

<plugin> <groupId>org.jacoco</groupId> <artifactId>jacoco-maven-plugin</artifactId> <version>0.8.7</version> <executions> <execution> <goals> <goal>prepare-agent</goal> </goals> </execution> <!-- attached to Maven test phase --> <execution> <id>report</id> <phase>test</phase> <goals> <goal>report</goal> </goals> </execution> </executions> </plugin>

 

Hope this helps.

Thanks

Sady_Rifat
Community Advisor
Community Advisor
April 19, 2023

Hello @aemlearner-1989 ,
Use SoarQube to check the unit test coverage. This will show you almost a similar coverage percentage as AEM Cloud. 

Use Jacoco Plugin to see the coverage percentage in sonarqube.

<plugin> <groupId>org.jacoco</groupId> <artifactId>jacoco-maven-plugin</artifactId> <version>0.8.4</version> <executions> <execution> <goals> <goal>prepare-agent</goal> </goals> </execution> <execution> <id>generate-code-coverage-report</id> <phase>test</phase> <goals> <goal>report</goal> </goals> </execution> </executions> </plugin>