Testing Articles
Articles covering unit testing, integration testing, and Testcontainers usage for Spring Boot test strategies.
-
How to Write Unit Tests for Controllers Using MockMvc in Spring Boot
A guide to writing Controller-specific tests that start the Spring context minimally with @WebMvcTest and verify HTTP requests and responses with MockMvc. Covers combining @MockBean with Mockito, JSON verification with jsonPath, and testing validation errors, with implementation examples.
-
How to Validate Spring Boot @ConfigurationProperties with Bean Validation - Detecting Errors at Startup and Testing
A step-by-step guide to combining @Validated and @NotNull/@Pattern with @ConfigurationProperties to instantly detect misconfiguration at application startup. Covers testing configuration validation with @SpringBootTest.
-
How to Test External API Calls with WireMock in Spring Boot
A practical guide to integrating WireMock into Spring Boot tests, defining external API stubs at the HTTP level for success cases, error cases, and timeouts. Also covers when to use Mockito vs WireMock.
-
Let's Write Tests in Spring Boot - Introduction to Unit Testing with JUnit and Mockito
A tutorial for those writing test code for Spring Boot applications for the first time. Step-by-step explanation of how to write unit tests for the Controller and Service layers using JUnit and Mockito, with @WebMvcTest and @MockBean.