From the course: Advanced Spring: Effective Integration Testing with Spring Boot

Unlock the full course today

Join today to access over 22,400 courses taught by industry experts or purchase this course individually.

Integration testing without making an external API call

Integration testing without making an external API call

From the course: Advanced Spring: Effective Integration Testing with Spring Boot

Start my 1-month free trial

Integration testing without making an external API call

- [Instructor] How can you counter integration testing for code that interacts with an external API? Imagine you have a component that's talking to another service and the service that you're calling in production environment, just isn't available to you in your test environment. Calling a staged version would be a better option but often you don't have it offered. For example, you're calling a live service like YouTube, Google, Facebook or Twitter API. APIs such as these have rate limits. So when you're running the tests you could exceed rate limits and your tests would fail or you would need to be careful not to exceed your rate limit and incur additional expenses. Then you also need to worry about storing credentials somewhere for your test use and it ends up way too complicated. Your best option is to mock out the service that you're calling. In the Spring world, we use the rest template or a WebClient to interact with external APIs. You could mock out rest template by mocking…

Contents