What it cover: Sling Models, services, utility logic in isolation Tooling: JUnit 5, Mockito, wcm.io AEM Mocks (`AEMContext`) `AEMContext` from
Testing and Debugging
Unit Test
- What it cover: Sling Models, services, utility logic in isolation
- Tooling: JUnit 5, Mockito, wcm.io AEM Mocks (
AEMContext)
Unit Test for Sling Models
AEMContext from io.wcm.mock.aem.junit5 gives an in-memory JCR+Sling+AEM context, so you can register a model, load content, and assert on the result - no running instance required.
Put the fixture JSON under src/test/resources mirroring the package. For a request-adaptable model, use ctx.request() as the adaptable and set ctx.currentResource(...) first.
Mocking OSGi services
Register mocks with Mockito and inject them into the context so ur model's @OSGiService/@Reference dependencies resolve:
What to unit-test
- Getter logic, defaults, and null/empty handling.
- Branching in
@PostContruct - Any Business rule (formatting, filtering, validation fallbacks)
Code coverage and quality gates
Jacoco
Debugging toolkit
Logs
crx-quickstart/log/error.logthe primary log.
CRXDE Lite
Confirm a property actually persisted, check sling:resourceType, inspect ACLs.
Request process, recent requets
system/console/requests shows full Sling processing of a request; which script/servlet rendered it, included resources, and timings.
Component and clientlib resolution
- Append
?debugClientLibs=trueto a page to load clientlibs unminified and see exactly which files are included. - Use
/libs/granite/ui/content/dumplibs.htmlto inspect clientlib categories and dependencies. - The HTL/Sling WCM debug filter (
?wcmmode=disabled) renders the page without editing chrome.
JaCoCo Unit Test Coverage
- Navigate to your projects root
/pom.xml - Add following line to
<properties>section - Add JaCoCo Plugin