AEM Unit & Integration Testing
Purpose
Implement comprehensive testing strategies for AEM projects including Sling Model unit tests, integration tests with AEM Mocks, UI tests with Selenium/Cypress, and CI pipeline test automation.
When to Use (Triggers)
- User mentions "testing," "unit test," "integration test," "AEM Mocks," or "test coverage"
- References to JUnit, Mockito, wcm.io testing, or AEM testing frameworks
- Questions about testing Sling Models, servlets, OSGi services, or workflows
- Requests involving test automation, CI/CD testing, or test-driven development
- Discussion of testing strategies for AEM components or custom code
Core Capabilities
- Write unit tests for Sling Models using AEM Mocks (io.wcm.testing)
- Implement integration tests with AEM context and repository state
- Configure UI testing with Selenium, Cypress, or Playwright for AEM pages
- Set up test fixtures using JCR content loading and mock resources
- Integrate testing into Maven build lifecycle and CI/CD pipelines
Domain Knowledge Required
Technical Foundation
- JUnit 5 architecture (extensions, parameterized tests, lifecycle)
- Mockito mocking framework (when/then, verify, argument captors)
- Test patterns (arrange-act-assert, test fixtures, test doubles)
- Code coverage tools (JaCoCo) and quality gates
AEM-Specific Context
- AEM Mocks (wcm.io) for in-memory AEM context simulation
- Sling Testing Mocks (ResourceResolver, SlingHttpServletRequest mocks)
- AEM Context JUnit extension for test resource loading
- Content loading from JSON fixtures for test data
- OSGi mock context for service testing
- AEM Cloud Service testing pipeline (unit, integration, UI tiers)
Implementation Approach
Step 1: Test Strategy Definition
Plan the testing approach for the project.
- Define test pyramid: unit (70%), integration (20%), UI (10%)
- Identify critical paths requiring integration/UI tests
- Establish code coverage targets (>80% for core bundle)
- Plan test data management strategy
Step 2: Unit Test Setup
Configure testing framework and write model tests.
- Add AEM Mocks dependencies to core module pom.xml
- Configure AemContext with required resource types and services
- Write tests for Sling Models (property injection, business logic)
- Test servlets with mock request/response objects
- Test OSGi services with mock dependencies
Step 3: Integration Testing
Implement tests requiring AEM context.
- Load test content from JSON fixtures into AemContext
- Test component rendering with HTL compilation (if applicable)
- Validate workflow execution with mock payloads
- Test query execution against loaded test content
- Verify ACL-dependent behavior with mock users
Step 4: UI Testing
Implement end-to-end browser testing.
- Configure Selenium/Cypress for AEM author and publish testing
- Create page objects for AEM editing interfaces
- Test component authoring workflow (add, configure, preview)
- Validate publish-side rendering and interaction
- Test responsive behavior across viewports
Step 5: CI/CD Integration
Automate test execution in build pipeline.
- Configure Maven Surefire/Failsafe for unit/integration separation
- Set up JaCoCo for code coverage reporting and enforcement
- Configure Cloud Manager quality gates for test results
- Implement test parallelization for faster feedback
Quality Checklist
Related Skills
- aem-component-development (testing components)
- aem-custom-osgi-services (testing services)
- aem-debugging-log-analysis (debugging test failures)
Example Use Cases
- Sling Model Testing: Write comprehensive unit tests for a product detail Sling Model verifying property injection, computed fields, null handling, and multi-value property processing using AEM Mocks.
- Workflow Process Step Testing: Test a custom workflow process step that validates page metadata completeness, using AemContext with loaded test content and mock WorkflowSession.
- Author Experience Testing: Implement Cypress tests validating the complete authoring workflow: create page, add component, configure dialog, preview, and publish.
Notes
- AEM Mocks simulate most AEM functionality in-memory — but not Oak queries or full OSGi container
- Use
@ExtendWith(AemContextExtension.class) for JUnit 5 AEM test context
- For Cloud Service: unit and integration tests run pre-deploy; UI tests run post-deploy on stage
- Keep unit tests fast (< 100ms each) — move slower tests to integration tier
1---2name: aem-unit-integration-testing3description: AEM Unit & Integration Testing4---5# AEM Unit & Integration Testing67## Purpose8Implement comprehensive testing strategies for AEM projects including Sling Model unit tests, integration tests with AEM Mocks, UI tests with Selenium/Cypress, and CI pipeline test automation.910## When to Use (Triggers)11- User mentions "testing," "unit test," "integration test," "AEM Mocks," or "test coverage"12- References to JUnit, Mockito, wcm.io testing, or AEM testing frameworks13- Questions about testing Sling Models, servlets, OSGi services, or workflows14- Requests involving test automation, CI/CD testing, or test-driven development15- Discussion of testing strategies for AEM components or custom code1617## Core Capabilities18- Write unit tests for Sling Models using AEM Mocks (io.wcm.testing)19- Implement integration tests with AEM context and repository state20- Configure UI testing with Selenium, Cypress, or Playwright for AEM pages21- Set up test fixtures using JCR content loading and mock resources22- Integrate testing into Maven build lifecycle and CI/CD pipelines2324## Domain Knowledge Required25### Technical Foundation26- JUnit 5 architecture (extensions, parameterized tests, lifecycle)27- Mockito mocking framework (when/then, verify, argument captors)28- Test patterns (arrange-act-assert, test fixtures, test doubles)29- Code coverage tools (JaCoCo) and quality gates3031### AEM-Specific Context32- AEM Mocks (wcm.io) for in-memory AEM context simulation33- Sling Testing Mocks (ResourceResolver, SlingHttpServletRequest mocks)34- AEM Context JUnit extension for test resource loading35- Content loading from JSON fixtures for test data36- OSGi mock context for service testing37- AEM Cloud Service testing pipeline (unit, integration, UI tiers)3839## Implementation Approach40### Step 1: Test Strategy Definition41Plan the testing approach for the project.42- Define test pyramid: unit (70%), integration (20%), UI (10%)43- Identify critical paths requiring integration/UI tests44- Establish code coverage targets (>80% for core bundle)45- Plan test data management strategy4647### Step 2: Unit Test Setup48Configure testing framework and write model tests.49- Add AEM Mocks dependencies to core module pom.xml50- Configure AemContext with required resource types and services51- Write tests for Sling Models (property injection, business logic)52- Test servlets with mock request/response objects53- Test OSGi services with mock dependencies5455### Step 3: Integration Testing56Implement tests requiring AEM context.57- Load test content from JSON fixtures into AemContext58- Test component rendering with HTL compilation (if applicable)59- Validate workflow execution with mock payloads60- Test query execution against loaded test content61- Verify ACL-dependent behavior with mock users6263### Step 4: UI Testing64Implement end-to-end browser testing.65- Configure Selenium/Cypress for AEM author and publish testing66- Create page objects for AEM editing interfaces67- Test component authoring workflow (add, configure, preview)68- Validate publish-side rendering and interaction69- Test responsive behavior across viewports7071### Step 5: CI/CD Integration72Automate test execution in build pipeline.73- Configure Maven Surefire/Failsafe for unit/integration separation74- Set up JaCoCo for code coverage reporting and enforcement75- Configure Cloud Manager quality gates for test results76- Implement test parallelization for faster feedback7778## Quality Checklist79- [ ] Unit tests cover all Sling Model business logic80- [ ] Integration tests validate critical content operations81- [ ] UI tests cover happy-path user journeys82- [ ] Code coverage meets minimum threshold (>80% core)83- [ ] Tests run reliably in CI without flakiness84- [ ] Test execution time acceptable (unit < 2min, integration < 5min)85- [ ] Test data managed independently (no shared mutable state)86- [ ] Failed tests produce clear, actionable error messages8788## Related Skills89- aem-component-development (testing components)90- aem-custom-osgi-services (testing services)91- aem-debugging-log-analysis (debugging test failures)9293## Example Use Cases941. **Sling Model Testing:** Write comprehensive unit tests for a product detail Sling Model verifying property injection, computed fields, null handling, and multi-value property processing using AEM Mocks.952. **Workflow Process Step Testing:** Test a custom workflow process step that validates page metadata completeness, using AemContext with loaded test content and mock WorkflowSession.963. **Author Experience Testing:** Implement Cypress tests validating the complete authoring workflow: create page, add component, configure dialog, preview, and publish.9798## Notes99- AEM Mocks simulate most AEM functionality in-memory — but not Oak queries or full OSGi container100- Use `@ExtendWith(AemContextExtension.class)` for JUnit 5 AEM test context101- For Cloud Service: unit and integration tests run pre-deploy; UI tests run post-deploy on stage102- Keep unit tests fast (< 100ms each) — move slower tests to integration tier