JUNIT 5: ArgumentCaptor with Mockito
Unit testing isn’t just about confirming your code works; it’s about ensuring it excels. Mockito, a trusted mock framework, introduces the ArgumentCaptor, a potent tool for honing your unit tests. This feature empowers you to capture and assert method arguments, leading to highly targeted tests. In this article, we’ll delve into the realm of ArgumentCaptor […]
JUNIT 5: JCR SQL 2 Unit Tests w/ Sling Servlet
I’ve dedicated quite a chunk of my personal time to crafting this blog post, and yes, I’ve rigorousl… This page is premium content. By supporting this website, please subscribe. Subscribe now for $1 for 1 month of premium content. Username or E-mail Password Remember Me Forgot Password
JUNIT5: What Exactly is org.mockito.junit.jupiter.MockitoExtension and Sling Model Example
org.mockito.junit.jupiter.MockitoExtension is a JUnit 5 extension provided by the Mockito library. It allows you to use the Mockito framework to create and inject mocked objects into your JUnit 5 test classes. This extension provides several features such as annotation-based mock creation, automatic detection of unused stubs, and support for the Mockito API. It enables you […]
AEM JUNIT5 with io.wcm.testing.mock.aem.junit5.AemContextExtension
io.wcm.testing.mock.aem.junit5.AemContextExtension is an extension for JUnit 5 that provides a way to run AEM (Adobe Experience Manager) unit tests with mocked AEM objects. This extension allows you to set up an AemContext object in your JUnit 5 test class, which provides access to mocked AEM objects such as the ResourceResolver, SlingSettings, and more. This makes […]
Mocking Static Methods in JUNIT5
PowerMock is a Java framework that allows you to unit test code that uses static methods, constructors, and private methods. PowerMock uses a combination of bytecode manipulation and reflection to enable the mocking of these types of methods. PowerMock is not officially supported by JUnit 5. PowerMock is built on top of EasyMock and provides […]
JUnit 5: Mocking the HttpClient in Java
Unfortunately when building AEM backend logic, the org.apache.http.client.HttpClient is non-trivial to write unit tests. In my case, I scavenged across the net to find a solution where you can make an GET and POST request via HttpClient in particular for AEM, and unit test is performing as expected. In order for me write successful to […]
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 […]