Testing Spring Boot Applications with Kotlin and Testcontainers

Recently I introduced Testcontainers for a Kotlin based Spring Boot application. I jumped right into the setup and immediately ran into an issue. Even though the interoperability of Java libraries and Kotlin is excellent, there is one thing you need to know when using Testcontainers with Kotlin. Continue reading to understand what it takes to

Read More

Improve build times with Context Caching from Spring Test

I’ve recently invested one day to improve the integration test setup for a larger project. The result is amazing: the build time (running mvn clean verify) went down from 25 minutes to 5 minutes by solely focussing on the test setup. All of this was possible by making the most of the Spring Test Context

Read More

Write Integration Tests For Your Spring WebSocket Endpoints

WebSockets allow establishing a full-duplex, two-way communication between the client and the server. With Spring WebSocket you can bootstrap your WebSocket application with ease. While there is great test support available for verifying Spring MVC endpoints (e.g. @RestController) using MockMvc, the support for testing WebSockets is rather limited. Continue reading to get an introduction to

Read More

Five JUnit 5 Features You Might Not Know Yet

Writing your first test with JUnit 5 is straightforward. Annotate your test method with @Test and verify the result using assertions. Apart from the basic testing functionality of JUnit 5, there are some features you might not have heard about (yet). Discover five JUnit 5 features I found useful while working with JUnit 5: test

Read More

Test Spring WebClient with MockWebServer from OkHttp

In one of the last blog post, I demonstrated how to test the Spring RestTemplate with @RestClientTest. With this elegant solution, you can easily test parts of your application that use the RestTemplate and mock HTTP responses. Unfortunately, this test setup does not work for the Spring WebClient.  It seems there won’t be an integration

Read More

Reuse Containers With Testcontainers for Fast Integration Tests

Testcontainers is now for almost a year part of my core testing libraries set. It allows you to control Docker containers for external parts of your application (e.g. database or messaging queue). This helps a lot when you write integration tests. The integration of Testcontainers with Spring Boot and JUnit is excellent and they improve

Read More

Test Spring Applications Using AWS With Testcontainers and LocalStack

If your Spring application uses AWS components like S3, SNS, or SQS you might wonder how to write effective integration tests. Should I mock the entire interaction with AWS? Should I duplicate the AWS infrastructure for testing? Is there maybe a local AWS clone available? With this blog post, you’ll learn how to write integration

Read More

Guide to Testing With the Spring Boot Starter Test

With Spring Boot, you only need one dependency to have a solid testing infrastructure: Spring Boot Starter Test. Using this starter, you don’t need to upgrade testing libraries and keep them compatible manually. You’ll get an opinionated set of libraries and can start writing tests without further setup effort. This guide gives you a first

Read More

Testing JSON Serialization With @JsonTest and Spring Boot

Spring Boot provides a set of annotations you can use for writing tests for a specific part of your application. These annotations take care of auto-configuring Spring’s ApplicationContext to include all beans you need. The most known ones are those of testing your web layer or database layer in isolation. There is also a lesser-known

Read More

Testing the Spring RestTemplate With @RestClientTest

While watching Andy Wilkinson’s great talk, Testing Spring Boot Applications on YouTube, he brought my attention to a hidden gem for testing the Spring RestTemplate. In the past, I always wondered how to write proper tests for client classes using the RestTemplate to fetch data from external services. In his presentation, he mentioned the @RestClientTest

Read More