Expand my Community achievements bar.

SOLVED

Check junit coverage on AEM cloud

Avatar

Level 5

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%

 

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @AEMLearner-1989 

The Junit coverage happens in the same way which @nitesh_kumar  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

View solution in original post

3 Replies

Avatar

Employee Advisor

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-... 

 

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/pro... 

 

Hope this helps!

 

Regards,

Nitesh

 

Avatar

Correct answer by
Community Advisor

Hi @AEMLearner-1989 

The Junit coverage happens in the same way which @nitesh_kumar  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

Avatar

Community Advisor

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>