Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.
SOLVED

CQ - Writing Server-side JUnit tests

Avatar

Former Community Member

I've been trying to write a JUnit test case for one of my Java class which creates a page with some given properties in CQ. For it, it need to get reference of SlingRepository and ResourceResolverFactory.  I was using http://sling.apache.org/documentation/development/sling-testing-tools.html#server-side-junit-tests-c... to get an idea on how to achieve this. In the document it says that a POST to "http://HOST:PORT/system/sling/junit/" path is used to execute tests on server side. But in CQ I get a 404 error for this path.

Is there any alternative URL in CQ for this? Or will really appreciate if anyone can suggest a better approach?

Thanks

1 Accepted Solution

Avatar

Correct answer by
Level 10

To get a ResourceResolverFactory.into an AEM service - you inject into your service that functions as the JUNIT test. 

//Inject a Sling ResourceResolverFactory
@Reference
private ResourceResolverFactory resolverFactory;'

 

To learn how to inject a ResourceResolverFactory into an AEM service -- see this community article:

 

http://helpx.adobe.com/experience-manager/using/querying-experience-manager-data-using1.html

 

 

Also -- we will add an article that talks about setting up JUNIT tests with AEM.

View solution in original post

1 Reply

Avatar

Correct answer by
Level 10

To get a ResourceResolverFactory.into an AEM service - you inject into your service that functions as the JUNIT test. 

//Inject a Sling ResourceResolverFactory
@Reference
private ResourceResolverFactory resolverFactory;'

 

To learn how to inject a ResourceResolverFactory into an AEM service -- see this community article:

 

http://helpx.adobe.com/experience-manager/using/querying-experience-manager-data-using1.html

 

 

Also -- we will add an article that talks about setting up JUNIT tests with AEM.