API Mocking and Stubbing Flashcards
7 cards from real API practice questions. Tap to flip, then mark Knew It or Still Learning — missed cards come back until you master them.
Read the first 7 API Mocking and Stubbing flashcards as text
What is an API mock in the context of software testing?
Answer: A simulated API that mimics the behavior of a real API with predefined responses
An API mock simulates the behavior of a real API by returning predefined responses, allowing testing without requiring the actual backend to be available.
What is the primary difference between a mock and a stub in API testing?
Answer: A stub returns canned responses without verifying interactions, while a mock also sets and verifies expectations about how it was called
A stub provides predefined responses without asserting how it was called, whereas a mock also records and verifies expectations about interactions.
Which scenario is best suited for using an API mock during development?
Answer: When the third-party API is unavailable, still under development, or too costly to call repeatedly
API mocking is ideal when the actual API is unavailable, under development, or when isolating the system under test from external dependencies is required.
In test double terminology, what is a 'fake'?
Answer: A working but simplified implementation that behaves correctly yet is unsuitable for production
A fake is a lightweight working implementation (such as an in-memory database) that functions correctly in tests but lacks the robustness needed for production.
What does 'service virtualization' mean in the context of API testing?
Answer: Creating simulated replicas of dependent services to enable testing when real services are unavailable
Service virtualization creates simulated versions of dependent services, enabling integration testing of complex systems when real backends are unavailable or impractical to use.
Which of the following is a primary benefit of API mocking during parallel team development?
Answer: Frontend and backend teams can develop and test independently against an agreed-upon API contract
API mocks allow frontend and backend teams to work in parallel by providing a stable, agreed-upon interface before the real backend is complete.
What is a 'spy' in test double terminology?
Answer: A test double that records calls made to it while still delegating to the real underlying implementation
A spy wraps the real implementation, recording interactions such as call count and arguments, while still invoking the actual code rather than replacing it.