MongoDB Testcontainers Setup for @DataMongoTest

Philip Riecks 

MongoDB is one of the NoSQL databases that Spring Boot offers great testing support for. Like all other test slice annotations from Spring Boot, when using @DataMongoTest, we'll

Read More

Use GreenMail For Spring Mail (JavaMailSender) JUnit 5 Integration Tests

Philip Riecks 

Sending emails is a common responsibility of enterprise applications. With the Spring Boot Starter Mail dependency, this becomes a trivial task. But how can we write integration tests

Read More

How to Test Java HTTP Client Usages (e.g. OkHttp, Apache HttpClient)

Philip Riecks 

Fetching data via HTTP from a remote system is a task almost every application has to solve. Fortunately, there are mature Java HTTP client libraries available that are

Read More

Override Spring Boot Configuration Properties For Tests

Philip Riecks 

As a general best practice, we should externalize configuration values for our applications. This allows overriding them per stage and e.g. connect to a PayPal test instance for

Read More

Fix No Qualifying Spring Bean Error For Spring Boot Tests

Philip Riecks 

When working for the first time with Spring, you might encounter several no qualifying bean exceptions when you try to start your application. The stack trace is quite

Read More

Spring Data JPA Persistence Layer Tests With @DataJpaTest

Philip Riecks 

Similar to testing our web layer in isolation with @WebMvcTest, Spring Boot provides a convenient way to test our Spring Boot JPA persistence layer. Using the @DataJpaTest test

Read More

Test Your Spring MVC Controller with the WebTestClient and MockMvc

Philip Riecks 

Starting with Spring Framework version 5.3 (part of Spring Boot since version 2.4.0) you can perform requests with the WebTestClient against MockMvc. This allows unifying the way you

Read More

@Mock vs. @MockBean When Testing Spring Boot Applications

Philip Riecks 

When you start testing your Spring Boot application sooner or later you'll stumble over @Mock and @MockBean. Both annotations create mock objects but with a slightly different purpose.

Read More

Write Concise Web Tests With Selenide and Testcontainers

Philip Riecks 

Good old web tests – extremely valuable, sometimes hard to maintain, and annoying once they get flaky. If you are familiar with Selenium, you might find your self-writing

Read More

Mocking Static Methods with Mockito (Java & Kotlin)

Philip Riecks 

Want to start a religious discussion? Start asking your teammates whether or not you should mock static method calls. It's debatable if this is an absolute no-go or

Read More