Posts

Showing posts from August, 2020

Unit testing in AEM - Debugging issues in Test class

Image
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 lis