Hello AEM Community,
We've recently migrated our environment from AEM 6.5 to AEM 6.5 LTS. Post-migration, we've observed that several of our previously passing test cases are now failing. These failures are impacting our deployment pipeline, and we're seeking insights to resolve them.
Details:
Migration Overview: Transitioned from AEM 6.5 to AEM 6.5 LTS following Adobe's recommended procedures.
Test Framework: Utilizing JUnit 5 for unit testing.
Issue Observed: Test cases that involve component initialization and resource adaptation are failing. Specifically, tests that previously passed are now encountering NullPointerException during the execution of the init() method in our models.
public final AemContext context = new AemContext(JCR_MOCK);
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.testing.sling-mock.junit5</artifactId>
<version>3.5.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.wcm</groupId>
<artifactId>io.wcm.testing.aem-mock.junit5</artifactId>
<version>5.6.10</version>
<exclusions>
<exclusion>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.scripting.api</artifactId>
</exclusion>
</exclusions>
</dependency>
Solved! Go to Solution.
Topics help categorize Community content and increase your ability to discover relevant content.
Views
Replies
Total Likes
Hi @PrakashBa2 ,
Try to update dependency to latest one:
<!-- https://mvnrepository.com/artifact/org.apache.sling/org.apache.sling.testing.sling-mock.junit5 -->
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.testing.sling-mock.junit5</artifactId>
<version>3.5.4</version>
<scope>test</scope>
</dependency>
Try to add dependency to org.osgi artifact. The class where compiler can't find constructor is in that library.
<!-- https://mvnrepository.com/artifact/org.osgi/osgi.core -->
<dependency>
<groupId>org.osgi</groupId>
<artifactId>osgi.core</artifactId>
<version>8.0.0</version>
<scope>provided</scope>
</dependency>
Best regards,
Kostiantyn Diachenko.
Hi @PrakashBa2 ,
Could you please provide next details about your failing tests?
- Example of mock initialization
- You init method where you are facing exception
- full stack trace of exception
These information should help us to localize problem and advice you with a recommendation to fix.
Best regards,
Kostiantyn Diachenko.
Views
Replies
Total Likes
@BeforeEach
public void init() throws Exception {
context.registerService(Replicator.class, replicator);
context.registerService(XXXService.class, xxxService);
lenient().when(resolverFactory.getServiceResourceResolver(anyMap())).thenReturn(resourceResolver);
lenient().when(resourceResolver.adaptTo(PageManager.class)).thenReturn(pageManager);
lenient().when(resourceResolver.adaptTo(Session.class)).thenReturn(session);
lenient().when(res.adaptTo(Node.class)).thenReturn(node);
lenient().when(resourceResolver.adaptTo(TagManager.class)).thenReturn(tagManager);
}
Views
Replies
Total Likes
Hi @PrakashBa2 ,
Try to update dependency to latest one:
<!-- https://mvnrepository.com/artifact/org.apache.sling/org.apache.sling.testing.sling-mock.junit5 -->
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.testing.sling-mock.junit5</artifactId>
<version>3.5.4</version>
<scope>test</scope>
</dependency>
Try to add dependency to org.osgi artifact. The class where compiler can't find constructor is in that library.
<!-- https://mvnrepository.com/artifact/org.osgi/osgi.core -->
<dependency>
<groupId>org.osgi</groupId>
<artifactId>osgi.core</artifactId>
<version>8.0.0</version>
<scope>provided</scope>
</dependency>
Best regards,
Kostiantyn Diachenko.
incresing version osgi.core resolves the issues Thank you
Views
Replies
Total Likes
Hi @PrakashBa2,
Your test cases are failing due to incompatible or outdated test dependencies after moving to AEM 6.5 LTS.
Try below steps steps to fix it
Update test dependencies in your pom.xml
:
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.testing.sling-mock.junit5</artifactId>
<version>3.6.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.wcm</groupId>
<artifactId>io.wcm.testing.aem-mock.junit5</artifactId>
<version>5.6.14</version>
<scope>test</scope>
</dependency>
Explicitly register your models in the test:
context.addModelsForClasses(MyModel.class);
Avoid NPEs in init()
:
Wrap logic defensively:
@PostConstruct
protected void init() {
if (someValue != null) {
// safe usage
}
}
Ensure test resource includes required properties:
context.create().resource("/content/test", "title", "Hello");
I hope that should resolve most post-migration test failures.
Views
Replies
Total Likes
<version>3.6.4</version>
<version>5.6.14</version>
are not exists
Views
Replies
Total Likes
@PrakashBa2 Could you check the latest version? Posted above code for your understanding.
Views
Replies
Total Likes
Hi @PrakashBa2 ,
The root cause of your issue:
Caused by: java.lang.NoSuchMethodError:
'void org.osgi.util.tracker.ServiceTracker.<init>(org.osgi.framework.BundleContext, java.lang.Class, org.osgi.util.tracker.ServiceTrackerCustomizer)'
means you're facing binary incompatibility between the org.osgi library and Apache Sling testing libraries when using Java 17 with JCR_MOCK in AEM 6.5 LTS.
This is a known problem due to outdated OSGi versions bundled in older Sling/AEM Mock libraries not working with Java 17’s stricter module access and updated APIs.
1. STOP Using JCR_MOCK
This mode is not Java 17 compatible anymore due to deep reflection and OSGi tracking issues.
Instead, use:
public final AemContext context = new AemContext(ResourceResolverType.RESOURCERESOLVER_MOCK);
This works with Java 17 and is safe unless you truly need a deep JCR node tree simulation (e.g., for custom node types or replication logic).
2. Upgrade Dependencies
Use the latest versions fully compatible with Java 17:
<dependency>
<groupId>io.wcm</groupId>
<artifactId>io.wcm.testing.aem-mock.junit5</artifactId>
<version>5.6.16</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.testing.sling-mock.junit5</artifactId>
<version>3.6.6</version>
<scope>test</scope>
</dependency>
You can verify these exist in Maven Central — both versions are valid and public.
3. Use Defensive Null Checks in @PostConstruct
@PostConstruct
protected void init() {
if (resource != null && resource.adaptTo(Node.class) != null) {
Node node = resource.adaptTo(Node.class);
// do your logic here safely
}
}
4. Define Java Version Explicitly in pom.xml
<properties>
<maven.compiler.release>17</maven.compiler.release>
</properties>
Regards,
Amit
Views
Replies
Total Likes
Hey Amit thank you for reply, we are using JCR API in code base ResourceResolverType.RESOURCERESOLVER_MOCK will return Null to JCR API
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies
Views
Likes
Replies