How to Speed Up Unit Tests in JUnit 5 AEM Projects with SLF4J-NOP
Optimizing the performance of unit tests in AEM projects is crucial for maintaining efficient development cycles. One effective method to achieve this is by disabling logging during test execution using the slf4j-nop library. Here’s why and how you can implement it, along with some performance benchmarks. Quick Links Why Disable Logs During Unit Tests? Adding […]
JUnit 4: AEM How to Mock @RequestAttribute value in Sling Model
This blog article will show code an example for JUnit 4, for how the Request Attribute is being mocked. This example will only cover mocking the @RequestAttribute with the use of @PostConstruct runtime phase, When you are in the code runtime phase of the constructor injection, this will not work (I spent a bit of […]
JUnit 4: AEM Sling Models Unit Test Constructor Injection Example
In this example, we will take a look at how we can mock Sling Model Constructor Injection dependencies for a JUnit 4 Unit test. Scenario: The Sling Model must expose either the PROD_URL or the DEAFULT_URL endpoint based on the run mode or request parameters; this is the requirement. The example below will demonstrate the […]
JUnit 4: AEM Sling Servlet Unit Test Example Using wcm.io AEM Mocks, Servlet by Resource Type
This article will demonstrate how to write AEM Unit tests for @SlingServletResourceTypes (OSGi DS 1.4 (R7) component property type annotations) using the Junit4 testing framework. With developers being more visual, the source code is posted below. Technologies here used are: AEM project archetype 19 (link) Mockito 2.27.0 (link) AEM Mocks JUnit 4 2.7.2 (link) This […]
JUnit 4: AEM WCMUsePojo Unit Test Example (Passing Paramaters)
This article will demonstrate how to write AEM Unit tests for building WCMUsePojo Java classes using the Junit4 testing framework. With developers being more visual, the source code is posted below. In this example, I am building a Sightly utils class that helps me append .html to page path that are configured by the author. […]
JUnit 4: AEM Sling Models Unit Test Example Using wcm.io AEM Mocks
Creating new AEM components, we sometimes need backend logic to compute user requests with business logic. There are multiple ways of doing so, like using the Java-Use API or Javascript-Use API, but the most popular and best practice of writing business logic for an AEM component will be using Sling Models. This article will demonstrate […]