@SpringBootTest loads and manages the Spring context for a test suite. In security tests, it provides the application environment in which endpoint behavior can be exercised. section 18.1
Use it with endpoint-focused security tests:
- Combine it with @AutoConfigureMockMvc and an autowired MockMvc field to call endpoints without starting a real client. section 18.1
- Exercise authentication and authorization by supplying either an empty or mock SecurityContext. section 18.1
- Verify that an unauthenticated request receives 401 Unauthorized while a mocked authenticated request succeeds with 200 OK. section 18.1
Minimal security test setup
@SpringBootTest @AutoConfigureMockMvc public class MainTests { @Autowired private MockMvc mvc; } section 18.1
Listing 18.1 A class for writing the tests
@SpringBootTest #1
public class MainTests {
}
View the minimal test class that uses @SpringBootTest to manage the Spring context. section 18.1

