CQ - Writing Server-side JUnit tests | Community
Skip to main content
October 16, 2015
Solved

CQ - Writing Server-side JUnit tests

  • October 16, 2015
  • 1 reply
  • 719 views

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-contributed-by-bundles 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

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by smacdonald2008

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.

1 reply

smacdonald2008
smacdonald2008Accepted solution
Level 10
October 16, 2015

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.