AEM Mocks Dependency

To use AEM Mocks, you have to include the AEM Mock Dependency for JUnit 5:


or for JUnit 4:


Additionally you will usually include additional testing dependencies for JUnit 5/4 itself, and probably other Libraries like Mockito. See also this guide how to migrate AEM Mocks from JUnit 4 to JUnit 5.

Log configuration for Unit Test

It is recommend to also include this dependency:


It contains a dependency to slf4-simple, and a sensible default configuration for SLF4J within the unit tests.

Further Sling and AEM dependencies

AEM Mocks (and the underlying libraries like Sling Mocks) are designed to work with a broader range of AEM versions and not only the current version (see AEM Version Support Matrix). AEM Mocks relies on a set of additional transitive Maven dependencies for certain internal Sling bundles that are not part of the AEM “Uber Jar”. For supporting also older version of AEM the versions included by default of those bundles are older ones as well, roughly matching the oldest supported AEM version. This may lead to the problem that some features e.g. in Sling Models that are available in the more recent version of AEM will not work in the unit tests.

The solution is to update the versions of the transitive dependencies to the version that are actually running in the AEM version you are targeting with your application.

To make this easier the project maintains the AEM Dependencies - which is a POM for each AEM version and each AEM service pack which includes:

  • The AEM Uber Jar Version
  • All “internal” dependencies required for AEM Mocks and Sling Mocks in the matching versions
  • Further dependencies includes in AEM but not in the AEM Uber Jar

You can include this POM with import scope into your project - example:

  <version><!-- AEM/Service Pack version --></version>

Order of dependencies

It is recommended to include the AEM Mock dependencies with test scope always before the AEM Uber Jar dependencies within you bundle projects.

Back to top

Version: 4.0.5-SNAPSHOT. Last Published: 2021-04-12.