Friday, 25 March 2016

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).
public class ExampleTest {

  public final AemContext context = new AemContext();

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


No comments :

Post a Comment