You are developing a Spring Boot application, and you need to perform integration tests on a service layer with external API calls. How would you ensure that the external API is not called during the test, and the service layer’s behavior is tested accurately?
- Use a real external API for testing.
- Disable the network during testing.
- Mock the external API calls using tools like WireMock or MockServer.
- Use a proxy server to intercept API requests.
Option 3 is the recommended approach. Tools like WireMock and MockServer allow you to create mock endpoints for external APIs, ensuring that actual API calls are not made during testing.
Loading...
Related Quiz
- To simulate HTTP requests and responses in integration tests, Spring Boot provides the _____ class, allowing for testing of controller methods without starting the server.
- In Mockito, the _____ method can be used to stub a return value for a method call.
- How can parameterized tests be created using JUnit?
- What is the significance of the @Transactional annotation in Spring Data JPA?
- How can you optimize the performance of Spring Data JPA repositories when dealing with large datasets?