Spring Boot Support for Unit Testing
Spring Boot provides test infrastructure so you can choose how much of the framework to load:
Pure Unit Test - No Spring context - Fast, isolated, uses mocks
@WebMvcTest - Only web layer -Controller logic with mocked services
@DataJpaTest - Only JPA layer- Repository logic with in-memory DB
@SpringBootTest - Full application context - Integration test (not unit!)
Tatooable - For unit testing, you don’t use @SpringBootTest.
Instead, you use JUnit 5 + Mockito with plain Java testing.
Conceptual Flow - Arrange - Act - Assert
Setup (Arrange):
Create a PaymentService instance.
Inject a mocked PaymentRepository.
Tell the mock what to return when called.
Execute (Act):
Call paymentService.processPayment(orderId).
Verify (Assert):
Check that the method returns the expected result.
Verify that the repository was called once with the correct argument.