Expand my Community achievements bar.

Elevate your expertise and be recognized as a true influencer! Nominations for the exclusive Adobe Community Advisor program 2023 are now OPEN.

it's still a problem, How to Unit test case for Sling delegation pattern?


Level 1

It's still a problem. I am using the latest AEM Maven Archetype to customize the Teaser component, but unable to pass my tests because of the delegation pattern. I scaveraged through the net and have already reviewed all the possible answers like:




@arunpatidar and other folks, can you please help me out by giving me a working version of a Delegation pattern?


Here's a very simple sling model component that needs JUNIT5. I am also on the latest AEM 6.5 version + Latest AEM Maven Archetype version


@Model(adaptables = SlingHttpServletRequest.class, resourceType = CustomTeaser.RESOURCE_TYPE, 
        defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL)
@Exporter(name = ExporterConstants.SLING_MODEL_EXPORTER_NAME, extensions = ExporterConstants.SLING_MODEL_EXTENSION)
public class CustomTeaser implements com.adobe.cq.wcm.core.components.models.Teaser {
    public static final String RESOURCE_TYPE = "mycomp/components/customteaser";

    @Via(type = ResourceSuperType.class)
    private com.adobe.cq.wcm.core.components.models.Teaser teaser;
    public String getTitle() {
        return teaser.getTitle();


Whenever I am using AEMContext or Mocks, while in debug mode, teaser is ALWAYS NULL.

5 Replies


Level 1

Hello, what is the CustomTeaserTest.json can you please share it?


Level 8

Hello @2490242973 ,

Please follow my article. I gave two examples for considering different cases. (Breadcrumb & Language Navigation).

Hope this will help you and your problem will be solved.


The main problem of the delegation pattern you just mention is null. This is solved.