Spring TestContext Framework, @SpringBootTest, Slice Tests and @MockBean
Learn Spring TestContext Framework, @SpringBootTest, Slice Tests and @MockBean (Phase 18 · Spring Testing (Core), Spring Core) with worked examples, diagrams and interview questions. Free on JavaSchoolLab.
TestContext framework • spring-test integrates the container with JUnit 5: @ExtendWith(SpringExtension.class) (included in Boot's annotations), @ContextConfiguration , @ActiveProfiles , @TestPropertySource , @DirtiesContext , @Sql , @Transactional on tests (auto-rollback), @DynamicPropertySource . The context is cached across tests with the same configuration: avoid unnecessary variations (different @MockBean sets, properties) to keep the suite fast.