Expand my Community achievements bar.

SOLVED

How to implement parallel execution of JUnit tests in AEM as a Cloud Service?

Avatar

Community Advisor

Hi All,

 

Has anyone done JUnit test execution in parallel mode in AEM Cloud? If yes, are any changes needed in Cloud Manager that we need to reach out to Adobe for?

 

I have tried updating junit-platform.properties under /src/test/resources but could not see any improvement in deployment time.

 

Please could someone advise.

 

Thanks,

Ram

Topics

Topics help categorize Community content and increase your ability to discover relevant content.

1 Accepted Solution

Avatar

Correct answer by
Level 8

I have tested this configuration in the Cloud Sandbox pipeline, and it has successfully reduced the build time.

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <configuration>
        <parallel>all</parallel> <!-- "methods" or "both" can also be used -->
        <threadCount>3</threadCount> <!-- Number of threads for parallel test execution -->
        <forkCount>3</forkCount> <!-- Number of JVM forks -->
        <reuseForks>true</reuseForks> <!-- Reuse forked JVMs for tests -->
        <useSystemClassLoader>false</useSystemClassLoader>
    </configuration>
</plugin>

 

View solution in original post

6 Replies

Avatar

Level 8

hi @rampai

In one of the projects I worked on, we implemented a CI/CD pipeline where the code was built in both our Jenkins instances and AEM CM in parallel. The CM outcome was mandatory for successfully completing the pipeline.

 

When we introduced parallel execution for JUnit tests, the build processing time dramatically decreased. TBH We also made some adjustments to test classes that contributed to this improvement. However, we remained dependent on the CM result. To address this, we updated our pipeline to generate visible reports before receiving the CM outcome. This allowed developers to check for any violations or issues raised from the SonarQube reports sooner.

 

In conclusion, I highly recommend using JUnit parallel execution because, with the right settings, it significantly speeds up development times.

Avatar

Community Advisor

Thanks @giuseppebag ,

 

Please could you confirm what adjustments you had to make to test classes as part of this improvement.

 

Regards,

Ram

Avatar

Level 8

I refactored test initialization so that heavyweight objects or resources (like database connections, file I/O, Context-Aware configs) are set up only once per test suite rather than before each test: I used class-level setup methods (for example, using JUnit’s @BeforeAll) to share common resources.

Where possible, I reused objects across multiple tests rather than instantiating them repeatedly.
Cached results or configurations that do not change between tests to cut down on repeated computation.

 

Avatar

Correct answer by
Level 8

I have tested this configuration in the Cloud Sandbox pipeline, and it has successfully reduced the build time.

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <configuration>
        <parallel>all</parallel> <!-- "methods" or "both" can also be used -->
        <threadCount>3</threadCount> <!-- Number of threads for parallel test execution -->
        <forkCount>3</forkCount> <!-- Number of JVM forks -->
        <reuseForks>true</reuseForks> <!-- Reuse forked JVMs for tests -->
        <useSystemClassLoader>false</useSystemClassLoader>
    </configuration>
</plugin>

 

Avatar

Community Advisor

Thanks @narendiran_ravi , 

 

I am checking this in my project. Will confirm if it worked.

 

Regards,

Ram

Avatar

Administrator

@rampai Did you find the suggestions helpful? Please let us know if you need more information. If a response worked, kindly mark it as correct for posterity; alternatively, if you found a solution yourself, we’d appreciate it if you could share it with the community. Thank you!



Kautuk Sahni