April 26, 2020
Estimated Post Reading Time ~

AEM Context JUnit Rule

The AEM mock context can be injected into a JUnit test using a custom JUnit rule named AemContext. This rules takes care of all initialization and cleanup tasks required to make sure all unit tests can run independently (and in parallel, if required).

Example:
public class ExampleTest {

 @Rule
 public final AemContext context = new AemContext();

 @Test
 public void testSomething() {
  Resource resource = context.resourceResolver().getResource("/content/sample/en");
  Page page = resource.adaptTo(Page.class);
  // further testing
 }

}

Read More


By aem4beginner

No comments:

Post a Comment

If you have any doubts or questions, please let us know.