@shyams67489715
The AemContext object provides access to mock implementations of:
- OSGi Component Context
- OSGi Bundle Context
- Sling Resource Resolver
- Sling Request
- Sling Response
- Sling Script Helper
Additionally it supports:
- Registering OSGi services
- Registering adapter factories
- Accessing JSON Importer
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
}
}The AEM mock context supports different resource resolver types (provided by the Sling Mocks implementation). Example:
private final AemContext context = new AemContext(ResourceResolverType.RESOURCERESOLVER_MOCK);
Reference: https://wcm.io/testing/aem-mock/usage.html
Thanks