Maven Setup For Testing Java Applications

Starting with a new programming language is always exciting. However, it can be overwhelming as we have to get comfortable with the language, the tools, conventions, and the general development workflow. This holds true for both developing and testing our applications. When testing Java applications with Maven, there are several concepts and conventions to understand:

Read More

Guide to @SpringBootTest for Spring Boot Integration Tests

With this guide, we’ll investigate the powerful @SpringBootTest annotation for writing integration tests. If you’re new to testing the Spring Boot applications, start with the testing overview and get a basic understanding of the testing swiss-army knife Spring Boot Starter Test. The Spring ecosystem seamlessly integrates various technologies and tools, but it also provides excellent

Read More

Creating Deep Stubs With Mockito to Chain Method Stubbing

Yet another blog post about a Mockito feature that we should rarely use: Mockito deep stubs. With this article, we’ll explore how deep stubbing can reduce the boilerplate stub setup for our tests when chaining fluent APIs of a mocked class. In general, “Every time a mock returns a mock, a fairy dies” should be

Read More

Spring Boot Unit and Integration Testing Overview

With this blog, you’ll get an overview of how unit and integration testing works with Spring Boot. On top of this, you’ll learn what Spring features and libraries to focus on first. This article acts as an aggregator and at several places, you’ll find links to other articles and guides that explain the concepts in

Read More

Initialization Strategies With Testcontainers For Integration Tests

Testcontainers offers several initialization strategies for our Docker containers when writing integration tests. Depending on the Docker image we use for our tests, we might have to perform additional setup steps. This includes adjusting the container configuration or populating data. With Testcontainers, we can tweak the container configuration either during runtime (executing commands inside the

Read More

OIDC Logout With AWS Cognito and Spring Security

With one of the previous blog posts, we configured a Thymeleaf Spring Boot application for an OAuth 2 Login with Spring Security and AWS Cognito. While this article focussed on the setup and login mechanism, the logout functionality was only half-way implemented. Our end-users are still logged in at the identity provider. Let’s adjust the

Read More

Java AWS Lambda Container Image Support (Complete Guide)

My original plan was to demo the container image support of AWS Lambda with a Java example that uses Selenium to scrape web pages. For Python and Node.js, there are a lot of examples available on the internet. I failed to get Chrome running for a Java AWS Lambda function with a custom Docker image.

Read More

Record Spring Events When Testing Spring Boot Applications

One of the core features of Spring is the event publishing functionality. We can use events to decouple parts of our application and implement a publish-subscribe pattern. One part of our application can publish an event that multiple listeners (even asynchronously) react to. As part of Spring Framework 5.3.3 (Spring Boot 2.4.2), we can now

Read More

Testing Spring Boot Applications With REST Assured

REST Assured is a Java DSL (Domain Specific Langauge) that aims to simplify testing REST APIs. It follows a BDD (Behavior Driven Development) approach and is influenced by testing APIs with dynamic languages like Groovy. We can use REST Assured to test the REST API of any Java project as it is framework independent. However,

Read More

Mock Java Constructors With Mockito | Configuration and Examples

Starting with Mockito version 3.5.0, we can now mock Java constructors with Mockito. This allows us to return a mock from every object construction for testing purposes. Similar to mocking static method calls with Mockito, we can define the scope of when to return a mock from a Java constructor for a particular Java class.

Read More