@SpringBootTest starts the Spring application context for a test, making application beans and configuration available. This supports integration tests that check how application parts work together. section 16.2 section 16.4
For a controller integration test, combine it with an injected WebApplicationContext and MockMvc. MockMvc sends simulated requests through the web setup without starting a real server. You can replace selected beans with mocks while keeping the rest of that setup in use. section 16.2
Listing 16.2 Configuring a MockMvc object
@SpringBootTest #A
public class TransferMoneyTests {
@Autowired
private WebApplicationContext context; #B
private MockMvc mockMvc;
@BeforeEach
void setup() {
this.mockMvc =
MockMvcBuilders.webAppContextSetup(context).build(); #C
}
}See how @SpringBootTest, WebApplicationContext, and MockMvc fit together in a small test-class setup. section 16.2
Test a money transfer endpoint
A controller integration test can send a simulated POST request to /transfer with MockMvc and check for an OK response. Mocking AccountRepository lets the test control repository behavior while exercising the Spring web setup. section 16.2



