Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn more

View all

Sign in to view all badges

SOLVED

Could not initialize class org.apache.sling.testing.mock.osgi.MockEventAdmin

ruchim71073425
Level 2
Level 2

Hello,

 

We are on AEM 6.4.8 and starting to setup unit test cases.

I have followed the article: 

https://experienceleague.adobe.com/docs/experience-manager-learn/getting-started-wknd-tutorial-devel...

 

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

1 Accepted Solution
asutosh_jena
Correct answer by
Community Advisor
Community Advisor

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! 

View solution in original post

1 Reply
asutosh_jena
Correct answer by
Community Advisor
Community Advisor

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! 

View solution in original post