Test Overview
This test starts the full Spring Boot application context and verifies that the main service bean is loaded correctly.
This test starts the full Spring Boot application context and verifies that the main service bean is loaded correctly.
import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import static org.junit.jupiter.api.Assertions.assertNotNull; @SpringBootTest public class ApplicationContextTest { @Autowired private MyService myService; @Test public void contextLoads() { assertNotNull(myService, "MyService bean should be loaded in the context"); } }
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts | JUnit test runner initializes | - | PASS |
| 2 | Spring Boot application context loads with @SpringBootTest | Full Spring context with all beans is created | - | PASS |
| 3 | JUnit injects MyService bean into test class | myService field is assigned a valid bean instance | - | PASS |
| 4 | Test method contextLoads() runs and asserts myService is not null | myService is a valid bean instance | assertNotNull(myService) | PASS |
| 5 | Test finishes successfully | Test runner reports success | - | PASS |