Unit Test Articles
2 articles about Unit Test. Explore Spring Boot implementation, design, and operations across related topics.
-
Mastering Mockito in Spring Boot Service Layer Tests - when, verify, ArgumentCaptor, and doThrow in Practice
Hands-on guide to Mockito's when/thenReturn, verify (times, never, inOrder), ArgumentCaptor, and doThrow/doAnswer for void methods, using OrderService tests. Also covers how to fix UnnecessaryStubbingException and InvalidUseOfMatchersException, and when to use @InjectMocks versus @MockitoBean.
-
Writing Tests in Spring Boot - An Introduction to Unit Testing with JUnit and Mockito
A step-by-step guide to writing Spring Boot unit tests with JUnit 5 and Mockito, split into the Service layer (@Mock/@InjectMocks) and the Controller layer (@WebMvcTest/@MockBean/MockMvc). Learn the Given-When-Then pattern, success and failure cases, and assertThrows through concrete code examples.