Expand my Community achievements bar.

Unit testing in AEM - Debugging issues in Test class | AEM Community Blog Seeding

Avatar

Administrator

BlogImage.jpg

Unit testing in AEM - Debugging issues in Test class by AEM Learnings

Abstract

This post is for illustrating the possible errors/exception we get while writing Test class.
Also highlights the possible ways of creating Test content and the ResourceResolverType available for creating AemContext (from io.wcm framework)

Test content :
Most important aspect of Unit Testing is creating Test content which in AEM sense is to provide a means of repository at the time of code build phase to test our Java code (written interacting with repo)
For creating the same, we already saw that there are 3 possible APIs - Content Loader, Content Builder and Resource Builder available.
Most often we use Content Loader making use of JSON file at class path and loading it to dummy content path. Below are the sample snippet making use of other two APIs.

Content Builder :
private final AemContext aemContext = new AemContext(ResourceResolverType.JCR_MOCK);
ContentBuilder contentBuilder = aemContext.create();
With this contentBuilder object, we can create page, asset, tag etc - Full list of methods available with ContentBuilder API is in doc.

Resource Builder:
private final AemContext aemContext = new AemContext(ResourceResolverType.JCR_MOCK);
ResourceBuilder rescBuilder= aemContext.build();
With this rescBuilder object, we can create resource with properties - Full list of methods available with ResourceBuilder API is in doc.

Read Full Blog

Unit testing in AEM - Debugging issues in Test class

Q&A

Please use this thread to ask the related questions.



Kautuk Sahni
Topics

Topics help categorize Community content and increase your ability to discover relevant content.

0 Replies