Describe how you would set up integration tests for a Spring Boot application that interacts with an external API.

Integration tests for a Spring Boot application that calls an external API use @SpringBootTest to load the full application context, combined with @MockBean to stub out the external API client so tests remain fast and independent of the real service's availability.

Key Points

Example

A test for an order-enrichment feature that calls a shipping-rates API mocks the ShippingRatesClient bean to return a fixed rate, then verifies the order service correctly applies that rate, without ever making a real HTTP call during the test run.

@SpringBootTest
class OrderServiceIntegrationTest {

    @MockBean
    private ShippingRatesClient shippingRatesClient;

    @Autowired
    private OrderService orderService;

    @Test
    void appliesShippingRate() {
        when(shippingRatesClient.getRate(any())).thenReturn(new Rate(9.99));
        Order order = orderService.createOrder(sampleRequest());
        assertEquals(9.99, order.getShippingCost());
    }
}

Interview Tip

A concise interview answer is

I'd use @SpringBootTest to load the full application context and @MockBean to stub out the external API client, so the test exercises real internal wiring without depending on the actual external service being up. I'd cover both successful responses and failure cases like timeouts, so the integration is verified end-to-end within the app's boundary.

Last updated: 16 July 2026

Previous question: What is the Spring Boot @Profile annotation used for?

Next question: How does the @Qualifier annotation work in Spring for managing dependencies?

More Spring Boot - Level IV (Advanced) interview questions

All Spring Boot - Level IV (Advanced) questions