java / beginner
Snippet
Basic Context Integration Test
The @SpringBootTest annotation is used for integration testing. It bootstraps the entire application context, allowing you to verify that all beans are wired correctly and the application can start.
snippet.java
1
2
3
4
5
6
7
@SpringBootTestclass ApplicationTests {@Testvoid contextLoads() {// This test will fail if the Spring context cannot start correctly}}
spring
Breakdown
1
@SpringBootTest
Tells Spring Boot to look for a main configuration class and use it to start the Spring context.
2
@Test
Standard JUnit annotation that marks the method as a test case.
3
void contextLoads()
A common test method used to verify that the application starts without crashing.