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 - A Fail Fast Implementation Guide to Detect Configuration Errors at Startup
Learn how to combine Spring Boot's @ConfigurationProperties with Bean Validation (@Validated/@NotBlank/@Pattern) to instantly detect configuration mistakes at application startup before they cause production incidents. Covers @Valid propagation for nested validation, how to read startup error messages, and lightweight testing with ApplicationContextRunner, all with implementation examples.
-
How to Test External API Calls with WireMock in Spring Boot - From import Setup to Practice
A practical guide to introducing WireMock into Spring Boot tests and defining external API stubs at the HTTP level, covering success cases, error cases, and timeouts. Also explains the correct import statement for WireMock 3.x's new package org.wiremock.client.WireMock, as well as criteria for choosing between Mockito and WireMock.
-
Writing Tests in Spring Boot - Introduction to Unit Testing with JUnit and Mockito
Learn how to write Spring Boot unit tests with JUnit 5 and Mockito, explained step by step for the Service layer (@Mock/@InjectMocks) and Controller layer (@WebMvcTest/@MockBean/MockMvc). Master the Given-When-Then pattern, success/failure cases, and assertThrows through concrete code examples.