Webmvctest Articles
2 articles about Webmvctest. Explore Spring Boot implementation, design, and operations across related topics.
-
How to Write Controller Unit Tests with MockMvc in Spring Boot - Introduction to @WebMvcTest
Achieve fast, DB-free, copy-paste-ready Controller unit tests with @WebMvcTest and MockMvc. Explains how to mock Services with @MockBean, validate JSON with jsonPath, handle validation errors (400), and integrate Security (@WithMockUser) with practical examples.
-
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.