In my blog post ‘How to use Spring Data’s Specification’ I showed you how you can write automated tests for your Spring Data Specifications. Although it explained how you can test a single specification, it missed a crucial part. The testing of composite specifications. In this follow-up post, I will close the gap left last time.
[Read More]How to use Spring Data's Specification
The query methods of Spring Data JPA are a convenient way to retrieve data from your database. By simply defining methods in an interface, the framework can derive queries. For more complicated things, you can also define named queries and write your own JPQL or native SQL queries. However, with a growing application, this approach shows its drawbacks. New use-cases require new, but only slightly different, queries. The results are growing repositories that become harder and harder to maintain.
In this blog post, I’ll show you how to use Spring Data’s Specification
to address this problem.
How to test any HTTP Client of your Spring Boot Application with MockServer
In an integration test, we want to test the interaction of several components of our application. However, as soon as one of these components communicates with a 3rd party service via HTTP, this can present us with a challenge. To be independent of this service, we have to mock it. In this blog post, I will show you how to do that with the help of MockServer.
[Read More]Testcontainers – How to use them in your Spring Boot Integration Tests
How to test the Web Services of your Spring Boot Application with @WebServiceServerTest
The idea of applications that provide their services over the web is anything but new. Chances are quite high that you already implemented such a service through a REST API. But before REST, there was a different approach to providing such services - SOAP. The release of Spring Boot 2.6.0 introduced a new test slice to test the components involved in providing these services. Let’s have a look at it!
[Read More]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.
How to test the Data Layer of your Spring Boot Application with @DataMongoTest
In this Blogpost, I will show you how to test the MongoDB-based data layer of your Spring Boot Application with @DataMongoTest
. While having a look at an example, we will bootstrap some test data, use an embedded in-memory MongoDB and write an actual MongoDB test.
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.
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.
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 @WebMvcTest
s.