Mockitobean Articles
2 articles about Mockitobean. Explore Spring Boot implementation, design, and operations across related topics.
-
Spring Boot @SpringBootTest webEnvironment Guide - Choosing Between MOCK, RANDOM_PORT, DEFINED_PORT, and NONE
A comparison table and working code clarify what each of the four @SpringBootTest webEnvironment modes (MOCK/RANDOM_PORT/DEFINED_PORT/NONE) does and does not start up. Covers replacing external dependencies with @MockitoBean, splitting scenarios with @Nested, and the cases where launching the full ApplicationContext is truly necessary.
-
How to Write Controller Unit Tests with MockMvc in Spring Boot - Introduction to @WebMvcTest
Learn how to unit test Controllers with MockMvc's perform and andExpect, using @WebMvcTest examples. Covers mocking Services with @MockitoBean in Boot 3.4+ (@MockBean in 3.3 and earlier), JSON verification with jsonPath, validation errors (400), and Security (@WithMockUser, csrf).