Hello,
We are on AEM 6.4.8 and starting to setup unit test cases.
I have followed the article:
I have added all dependencies as mentioned in the article, but when trying to run the test, getting the following error:
java.lang.NoClassDefFoundError: Could not initialize class org.apache.sling.testing.mock.osgi.MockEventAdmin
at org.apache.sling.testing.mock.osgi.context.OsgiContextImpl.registerDefaultServices(OsgiContextImpl.java:68)
at org.apache.sling.testing.mock.osgi.context.OsgiContextImpl.setUp(OsgiContextImpl.java:49)
at org.apache.sling.testing.mock.sling.context.SlingContextImpl.setUp(SlingContextImpl.java:117)
at io.wcm.testing.mock.aem.context.AemContextImpl.setUp(AemContextImpl.java:96)
at io.wcm.testing.mock.aem.junit5.AemContext.setUpContext(AemContext.java:100)
at io.wcm.testing.mock.aem.junit5.AemContextExtension.setAemContextInStore(AemContextExtension.java:73)
at io.wcm.testing.mock.aem.junit5.AemContextExtension.postProcessTestInstance(AemContextExtension.java:63)
at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.lambda$invokeTestInstancePostProcessors$5(ClassBasedTestDescriptor.java:341)
at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.executeAndMaskThrowable(ClassBasedTestDescriptor.java:346)
at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.lambda$invokeTestInstancePostProcessors$6(ClassBasedTestDescriptor.java:341)
at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
at java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:175)
Any help will be appreciated.
Thanks
Ruchi
Solved! Go to Solution.
Views
Replies
Total Likes
Hi @ruchim71073425
Can you please add the following maven dependency and retry?
<!-- https://mvnrepository.com/artifact/org.apache.sling/org.apache.sling.testing.osgi-mock.junit5 -->
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.testing.osgi-mock.junit5</artifactId>
<version>3.0.0</version>
<scope>test</scope>
</dependency>
Thanks!
Hi @ruchim71073425
Can you please add the following maven dependency and retry?
<!-- https://mvnrepository.com/artifact/org.apache.sling/org.apache.sling.testing.osgi-mock.junit5 -->
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.testing.osgi-mock.junit5</artifactId>
<version>3.0.0</version>
<scope>test</scope>
</dependency>
Thanks!
Assuming you're on jdk8, I might have had a similar issue in the past. It was specific to my local machine since our pipelines were running fine.
Then realized that a system update had reset some env variables and my java home was reset to jdk11 which was subsequently getting picked up by mvn
The tests started running fine was the env variables were reset and mvn picked up jdk 8 as the version being used.
$ mvn -version
Apache Maven 3.6.2 (40f52333136460af0dc0d7232c0dc0bcf0d9e117; 2019-08-27T08:06:16-07:00)
Maven home: C:\Users\<xx>\Work\apache-maven-3.6.2
Java version: 1.8.0_301, vendor: Oracle Corporation, runtime: C:\Program Files\Java\jdk1.8.0_301\jre
....
Views
Likes
Replies
Views
Likes
Replies