How to test the REST Clients of your Spring Boot Application with @RestClientTest

In this Blogpost, I will show you how to test the REST Clients of your Spring Boot Application with @RestClientTest. We will implement a repository that will fetch its data from the Star Wars API. By using the MockRestServiceServer we are going to mock the real API, to isolate our tests and fake inputs for our REST client to test its behavior. In the last part, I will show you how you can isolate the individual tests from another.

[Read More]

How to test the Data Layer of your Spring Boot Application with @DataJpaTest

In this Blogpost, I will show you how to test the JPA-based data layer of your Spring Boot Application with @DataJpaTest. You will learn what happens when you use this annotation on a test class and a few ways to customize the default behavior. We will also have a look at an example where we will bootstrap some test data in different ways and write an actual JPA test.

[Read More]

How to test the Data Layer of your Spring Boot Application – an Overview

In this blog post, I will give you an overview of Spring Boot’s capabilities to test the data layer of your application.
There is a vast amount of technologies to choose from when it comes to loading and persisting data. There are not only completely different types of data stores but also different ways to communicate with them. Which combination is the most fitting, depends on your application. Whatever you choose, you should consider testing the components communicating with your data store, to prevent working with the wrong data.
The @Data*Test annotations of Spring Boot offer a great way to test these components in isolation while providing some handy niceties to make your life easier.

[Read More]

How to test the Web Layer of your Spring Boot Application with @WebMvcTest

The Web Layer is an interface that enables systems to access the business logic of your application. It is responsible to translate the web-based requests into a format that is used in the core of your system. Also, it transforms the internally used formats into a response that can be sent over the web.
To lower the risk of changing the behavior of your Web Layer by accident, you can use @WebMvcTests.

[Read More]

How to test JSON (de-)serialization in your Spring Boot application with @JsonTest

JSON is a popular data format that is widely used in the communication between systems. Most of the time, I see it being sent with an HTTP request or as the content of a message in a message bus. To ensure the stability of the communication between such systems, it is important that the structure of the JSON does not change without the agreement of both participants. With @JsonTest, Spring Boot contains a handy tool to test the serialization of Java objects into JSON and vice versa.

[Read More]