Practise vocabulary for test doubles in API testing: mock, stub, fake, spy, and the Pact-specific mock provider.
0 / 25 completed
1 / 25
A ___ is a test double that returns hard-coded responses to specific calls, without verifying how it was called.
A stub provides predefined responses to calls — it controls the indirect inputs to the system under test. Unlike a mock, a stub doesn't verify expectations about how it was called.
2 / 25
A ___ records calls made to it and allows assertions on how many times it was called and with which arguments.
A spy wraps a real or stub implementation and records interactions (call count, arguments). This allows both the return value control of a stub and the call-count assertions of a mock.
3 / 25
A ___ is a working implementation of a dependency, simplified for testing — for example, an in-memory database instead of a real one.
A fake has working business logic but is simplified compared to production — like an in-memory SQLite database instead of PostgreSQL. Fakes are functional but not suitable for production use.
4 / 25
In Pact, the ___ acts as a replacement for the real provider during consumer tests, verifying the consumer sends correct requests.
The Pact mock provider is a local HTTP server that Pact sets up during consumer tests. It responds to requests as defined in the interactions and records them to generate the pact file. It also verifies the consumer sends correct requests.
5 / 25
'Mock drift' refers to the problem where ___, making tests pass while the real API has diverged.
Mock drift occurs when mocks are not updated as the real API evolves. Tests pass against stale mocks while the real integration is broken. Consumer-driven contract testing solves this by continuously verifying the consumer's expectations against the real provider.
6 / 25
During a code review of PR #1234, Sarah pointed out that the team was using mocks extensively for testing the payment gateway integration. John responded with: 'I'm finding stubs really helpful because they let me control the response data directly and avoid complex setup.' Which statement best describes the key difference between a mock and a stub in this context?
A) A stub is a fully functional implementation of the dependency, while a mock is a simplified version. B) A mock allows you to control the responses, whereas a stub focuses on recording method calls for verification. C) A stub is used primarily to verify interactions with a real dependency, while a mock provides a controlled, isolated environment. D) Both mocks and stubs are interchangeable terms referring to test doubles.
The core distinction lies in their purpose. A mock object is designed to mimic the behavior of a real dependency, allowing developers to control the responses it returns – this is what John was doing. Conversely, a stub primarily focuses on recording method calls made to it; its main function is for verification purposes, ensuring that the code under test actually interacts with the dependency as expected. Option A incorrectly describes the nature of mocks and stubs. Option D is simply inaccurate – they are distinct tools.
7 / 25
During a Slack discussion regarding the upcoming release of our new user onboarding flow, Alex posted: 'I'm using stubs to mock out the CRM API responses. It's much faster than setting up mocks and dealing with all the configuration.' Based on this statement, what is the primary advantage of utilizing stubs in this scenario?
A) Stubs are more flexible and can simulate complex interactions between different components. B) Stubs provide a controlled environment for testing by allowing developers to directly define and return specific data values without needing to verify call details. C) Stubs are primarily used for verifying that the dependent service is called with the correct arguments, ensuring proper integration. D) Stubs are ideal for simulating real-world user behavior during acceptance tests.
The question asks about the primary advantage of using stubs in this context. While mocks *can* control responses, that's not their core purpose. Stubs excel at providing simplified, controlled data directly to the test code – as Alex states, it's 'much faster' because you don't need to configure complex verification rules. Options A and C are incorrect because stubs aren't inherently flexible or focused on argument verification; they're about direct data control. Option D is a misapplication of stub usage.
8 / 25
{code}
During a code review of PR #4567, David highlighted that the team's tests for the user authentication service were relying heavily on mocks. He said: 'We need to ensure our mocks are actually verifying that we're calling the correct methods on the real authentication provider, not just getting back some dummy responses.' Which statement best reflects David's concern?
A) Mocks are inherently less reliable than stubs for testing because they don't provide a direct path to verify interactions. B) The primary purpose of a mock is to simulate the behavior of a real dependency, and ensuring that method calls are verified within the mock is crucial for effective test coverage. C) Stubs are better suited for mocking dependencies than mocks, as they don't require verification logic. D) Verification of method calls on a mock is solely necessary when testing asynchronous operations.
The correct answer (B) accurately captures David's concern. Mocks are designed to *simulate* dependencies, but without verifying that the real dependency is being called correctly with the intended arguments and in the expected order, the test isn't truly testing the integration. Options A mischaracterizes mock reliability; C incorrectly states stubs don't require verification, and D focuses on a specific (asynchronous) scenario which isn't the core issue David raised.
9 / 25
During a code review of PR #7890, Maria noted that the team was using stubs to test the new order processing service. She commented: 'I'm finding it easier to use stubs here because I need to control the exact data returned by the inventory service – things like stock levels can change rapidly and would make our tests unstable if we were relying on a live dependency.' Considering Maria's feedback, what is the most significant benefit of employing stubs in this specific testing scenario?
This question tests understanding of the core purpose of stubs – controlled data return. Maria's comment highlights that stock levels changing in a live dependency would cause test failures, which is precisely what a stub avoids by allowing developers to define and control the response data directly. The incorrect options either misrepresent the role of stubs (flexibility, verification) or conflate their function with mocks.
10 / 25
During a code review of PR #9123, Ben observed the team's approach to testing the shipping service. He stated: 'I'm using mocks extensively because I want to guarantee that every call to the external shipping API returns a successful response, regardless of any potential network issues or rate limiting.' Considering Ben's statement and his goal, which option best describes the primary reason for utilizing mocks in this context? A) Mocks are ideal for simulating complex interactions between different services, requiring extensive configuration. B) Mocks allow developers to control the responses returned by a dependency, ensuring consistent test results even under adverse conditions. C) Stubs are preferred when you need to verify method calls and argument types during testing. D) Stubs are best suited for mocking simple dependencies with minimal interaction logic.
The correct answer (B) accurately reflects Ben's goal: he wants to isolate his tests from external API inconsistencies. Mocks provide the control needed to return a successful response regardless of network problems or rate limits – this is a key benefit of using mocks for ensuring test stability and predictable outcomes. Options A, C, and D misrepresent the core purpose of mocks; stubs are primarily used for verification, not controlling responses directly.
11 / 25
During a code review of PR #1234, Sarah pointed out that the team was using mocks extensively for testing the payment gateway integration. John responded with: 'I'm finding stubs really helpful because they let me control the response data directly and avoid complex setup.' Which statement best describes the key difference between a mock and a stub in this context?
A) A stub is a fully functional implementation of the dependency, while a mock is a simplified version. B) A mock allows you to control the responses, whereas a stub focuses on recording method calls for verification. C) A stub is used primarily to verify interactions with a real dependency, while a mock provides a controlled, isolated environment. D) Both mocks and stubs are interchangeable terms referring to test doubles.
The core distinction lies in their purpose. A mock object is designed to mimic the behavior of a real dependency, allowing developers to control the responses it returns – this is what John was doing. Conversely, a stub primarily focuses on recording method calls made to it; its main function is for verification purposes, ensuring that the code under test actually interacts with the dependency as expected. Option A incorrectly describes the nature of mocks and stubs. Option D is simply inaccurate – they are distinct tools.
12 / 25
During a Slack discussion regarding the upcoming release of our new user onboarding flow, Alex posted: 'I'm using stubs to mock out the CRM API responses. It's much faster than setting up mocks and dealing with all the configuration.' Based on this statement, what is the primary advantage of utilizing stubs in this scenario?
A) Stubs are more flexible and can simulate complex interactions between different components. B) Stubs provide a controlled environment for testing by allowing developers to directly define and return specific data values without needing to verify call details. C) Stubs are primarily used for verifying that the dependent service is called with the correct arguments, ensuring proper integration. D) Stubs are ideal for simulating real-world user behavior during acceptance tests.
The question asks about the primary advantage of using stubs in this context. While mocks *can* control responses, that's not their core purpose. Stubs excel at providing simplified, controlled data directly to the test code – as Alex states, it's 'much faster' because you don't need to configure complex verification rules. Options A and C are incorrect because stubs aren't inherently flexible or focused on argument verification; they're about direct data control. Option D is a misapplication of stub usage.
13 / 25
{code}
During a code review of PR #4567, David highlighted that the team's tests for the user authentication service were relying heavily on mocks. He said: 'We need to ensure our mocks are actually verifying that we're calling the correct methods on the real authentication provider, not just getting back some dummy responses.' Which statement best reflects David's concern?
A) Mocks are inherently less reliable than stubs for testing because they don't provide a direct path to verify interactions. B) The primary purpose of a mock is to simulate the behavior of a real dependency, and ensuring that method calls are verified within the mock is crucial for effective test coverage. C) Stubs are better suited for mocking dependencies than mocks, as they don't require verification logic. D) Verification of method calls on a mock is solely necessary when testing asynchronous operations.
The correct answer (B) accurately captures David's concern. Mocks are designed to *simulate* dependencies, but without verifying that the real dependency is being called correctly with the intended arguments and in the expected order, the test isn't truly testing the integration. Options A mischaracterizes mock reliability; C incorrectly states stubs don't require verification, and D focuses on a specific (asynchronous) scenario which isn't the core issue David raised.
14 / 25
During a code review of PR #7890, Maria noted that the team was using stubs to test the new order processing service. She commented: 'I'm finding it easier to use stubs here because I need to control the exact data returned by the inventory service – things like stock levels can change rapidly and would make our tests unstable if we were relying on a live dependency.' Considering Maria's feedback, what is the most significant benefit of employing stubs in this specific testing scenario?
This question tests understanding of the core purpose of stubs – controlled data return. Maria's comment highlights that stock levels changing in a live dependency would cause test failures, which is precisely what a stub avoids by allowing developers to define and control the response data directly. The incorrect options either misrepresent the role of stubs (flexibility, verification) or conflate their function with mocks.
15 / 25
During a code review of PR #9123, Ben observed the team's approach to testing the shipping service. He stated: 'I'm using mocks extensively because I want to guarantee that every call to the external shipping API returns a successful response, regardless of any potential network issues or rate limiting.' Considering Ben's statement and his goal, which option best describes the primary reason for utilizing mocks in this context? A) Mocks are ideal for simulating complex interactions between different services, requiring extensive configuration. B) Mocks allow developers to control the responses returned by a dependency, ensuring consistent test results even under adverse conditions. C) Stubs are preferred when you need to verify method calls and argument types during testing. D) Stubs are best suited for mocking simple dependencies with minimal interaction logic.
The correct answer (B) accurately reflects Ben's goal: he wants to isolate his tests from external API inconsistencies. Mocks provide the control needed to return a successful response regardless of network problems or rate limits – this is a key benefit of using mocks for ensuring test stability and predictable outcomes. Options A, C, and D misrepresent the core purpose of mocks; stubs are primarily used for verification, not controlling responses directly.
16 / 25
During a code review of PR #1234, Sarah pointed out that the team was using mocks extensively for testing the payment gateway integration. John responded with: 'I'm finding stubs really helpful because they let me control the response data directly and avoid complex setup.' Which statement best describes the key difference between a mock and a stub in this context?
A) A stub is a fully functional implementation of the dependency, while a mock is a simplified version. B) A mock allows you to control the responses, whereas a stub focuses on recording method calls for verification. C) A stub is used primarily to verify interactions with a real dependency, while a mock provides a controlled, isolated environment. D) Both mocks and stubs are interchangeable terms referring to test doubles.
The core distinction lies in their purpose. A mock object is designed to mimic the behavior of a real dependency, allowing developers to control the responses it returns – this is what John was doing. Conversely, a stub primarily focuses on recording method calls made to it; its main function is for verification purposes, ensuring that the code under test actually interacts with the dependency as expected. Option A incorrectly describes the nature of mocks and stubs. Option D is simply inaccurate – they are distinct tools.
17 / 25
During a Slack discussion regarding the upcoming release of our new user onboarding flow, Alex posted: 'I'm using stubs to mock out the CRM API responses. It's much faster than setting up mocks and dealing with all the configuration.' Based on this statement, what is the primary advantage of utilizing stubs in this scenario?
A) Stubs are more flexible and can simulate complex interactions between different components. B) Stubs provide a controlled environment for testing by allowing developers to directly define and return specific data values without needing to verify call details. C) Stubs are primarily used for verifying that the dependent service is called with the correct arguments, ensuring proper integration. D) Stubs are ideal for simulating real-world user behavior during acceptance tests.
The question asks about the primary advantage of using stubs in this context. While mocks *can* control responses, that's not their core purpose. Stubs excel at providing simplified, controlled data directly to the test code – as Alex states, it's 'much faster' because you don't need to configure complex verification rules. Options A and C are incorrect because stubs aren't inherently flexible or focused on argument verification; they're about direct data control. Option D is a misapplication of stub usage.
18 / 25
{code}
During a code review of PR #4567, David highlighted that the team's tests for the user authentication service were relying heavily on mocks. He said: 'We need to ensure our mocks are actually verifying that we're calling the correct methods on the real authentication provider, not just getting back some dummy responses.' Which statement best reflects David's concern?
A) Mocks are inherently less reliable than stubs for testing because they don't provide a direct path to verify interactions. B) The primary purpose of a mock is to simulate the behavior of a real dependency, and ensuring that method calls are verified within the mock is crucial for effective test coverage. C) Stubs are better suited for mocking dependencies than mocks, as they don't require verification logic. D) Verification of method calls on a mock is solely necessary when testing asynchronous operations.
The correct answer (B) accurately captures David's concern. Mocks are designed to *simulate* dependencies, but without verifying that the real dependency is being called correctly with the intended arguments and in the expected order, the test isn't truly testing the integration. Options A mischaracterizes mock reliability; C incorrectly states stubs don't require verification, and D focuses on a specific (asynchronous) scenario which isn't the core issue David raised.
19 / 25
During a code review of PR #7890, Maria noted that the team was using stubs to test the new order processing service. She commented: 'I'm finding it easier to use stubs here because I need to control the exact data returned by the inventory service – things like stock levels can change rapidly and would make our tests unstable if we were relying on a live dependency.' Considering Maria's feedback, what is the most significant benefit of employing stubs in this specific testing scenario?
This question tests understanding of the core purpose of stubs – controlled data return. Maria's comment highlights that stock levels changing in a live dependency would cause test failures, which is precisely what a stub avoids by allowing developers to define and control the response data directly. The incorrect options either misrepresent the role of stubs (flexibility, verification) or conflate their function with mocks.
20 / 25
During a code review of PR #9123, Ben observed the team's approach to testing the shipping service. He stated: 'I'm using mocks extensively because I want to guarantee that every call to the external shipping API returns a successful response, regardless of any potential network issues or rate limiting.' Considering Ben's statement and his goal, which option best describes the primary reason for utilizing mocks in this context? A) Mocks are ideal for simulating complex interactions between different services, requiring extensive configuration. B) Mocks allow developers to control the responses returned by a dependency, ensuring consistent test results even under adverse conditions. C) Stubs are preferred when you need to verify method calls and argument types during testing. D) Stubs are best suited for mocking simple dependencies with minimal interaction logic.
The correct answer (B) accurately reflects Ben's goal: he wants to isolate his tests from external API inconsistencies. Mocks provide the control needed to return a successful response regardless of network problems or rate limits – this is a key benefit of using mocks for ensuring test stability and predictable outcomes. Options A, C, and D misrepresent the core purpose of mocks; stubs are primarily used for verification, not controlling responses directly.
21 / 25
During a code review of PR #1234, Sarah pointed out that the team was using mocks extensively for testing the payment gateway integration. John responded with: 'I'm finding stubs really helpful because they let me control the response data directly and avoid complex setup.' Which statement best describes the key difference between a mock and a stub in this context?
A) A stub is a fully functional implementation of the dependency, while a mock is a simplified version. B) A mock allows you to control the responses, whereas a stub focuses on recording method calls for verification. C) A stub is used primarily to verify interactions with a real dependency, while a mock provides a controlled, isolated environment. D) Both mocks and stubs are interchangeable terms referring to test doubles.
The core distinction lies in their purpose. A mock object is designed to mimic the behavior of a real dependency, allowing developers to control the responses it returns – this is what John was doing. Conversely, a stub primarily focuses on recording method calls made to it; its main function is for verification purposes, ensuring that the code under test actually interacts with the dependency as expected. Option A incorrectly describes the nature of mocks and stubs. Option D is simply inaccurate – they are distinct tools.
22 / 25
During a Slack discussion regarding the upcoming release of our new user onboarding flow, Alex posted: 'I'm using stubs to mock out the CRM API responses. It's much faster than setting up mocks and dealing with all the configuration.' Based on this statement, what is the primary advantage of utilizing stubs in this scenario?
A) Stubs are more flexible and can simulate complex interactions between different components. B) Stubs provide a controlled environment for testing by allowing developers to directly define and return specific data values without needing to verify call details. C) Stubs are primarily used for verifying that the dependent service is called with the correct arguments, ensuring proper integration. D) Stubs are ideal for simulating real-world user behavior during acceptance tests.
The question asks about the primary advantage of using stubs in this context. While mocks *can* control responses, that's not their core purpose. Stubs excel at providing simplified, controlled data directly to the test code – as Alex states, it's 'much faster' because you don't need to configure complex verification rules. Options A and C are incorrect because stubs aren't inherently flexible or focused on argument verification; they're about direct data control. Option D is a misapplication of stub usage.
23 / 25
{code}
During a code review of PR #4567, David highlighted that the team's tests for the user authentication service were relying heavily on mocks. He said: 'We need to ensure our mocks are actually verifying that we're calling the correct methods on the real authentication provider, not just getting back some dummy responses.' Which statement best reflects David's concern?
A) Mocks are inherently less reliable than stubs for testing because they don't provide a direct path to verify interactions. B) The primary purpose of a mock is to simulate the behavior of a real dependency, and ensuring that method calls are verified within the mock is crucial for effective test coverage. C) Stubs are better suited for mocking dependencies than mocks, as they don't require verification logic. D) Verification of method calls on a mock is solely necessary when testing asynchronous operations.
The correct answer (B) accurately captures David's concern. Mocks are designed to *simulate* dependencies, but without verifying that the real dependency is being called correctly with the intended arguments and in the expected order, the test isn't truly testing the integration. Options A mischaracterizes mock reliability; C incorrectly states stubs don't require verification, and D focuses on a specific (asynchronous) scenario which isn't the core issue David raised.
24 / 25
During a code review of PR #7890, Maria noted that the team was using stubs to test the new order processing service. She commented: 'I'm finding it easier to use stubs here because I need to control the exact data returned by the inventory service – things like stock levels can change rapidly and would make our tests unstable if we were relying on a live dependency.' Considering Maria's feedback, what is the most significant benefit of employing stubs in this specific testing scenario?
This question tests understanding of the core purpose of stubs – controlled data return. Maria's comment highlights that stock levels changing in a live dependency would cause test failures, which is precisely what a stub avoids by allowing developers to define and control the response data directly. The incorrect options either misrepresent the role of stubs (flexibility, verification) or conflate their function with mocks.
25 / 25
During a code review of PR #9123, Ben observed the team's approach to testing the shipping service. He stated: 'I'm using mocks extensively because I want to guarantee that every call to the external shipping API returns a successful response, regardless of any potential network issues or rate limiting.' Considering Ben's statement and his goal, which option best describes the primary reason for utilizing mocks in this context? A) Mocks are ideal for simulating complex interactions between different services, requiring extensive configuration. B) Mocks allow developers to control the responses returned by a dependency, ensuring consistent test results even under adverse conditions. C) Stubs are preferred when you need to verify method calls and argument types during testing. D) Stubs are best suited for mocking simple dependencies with minimal interaction logic.
The correct answer (B) accurately reflects Ben's goal: he wants to isolate his tests from external API inconsistencies. Mocks provide the control needed to return a successful response regardless of network problems or rate limits – this is a key benefit of using mocks for ensuring test stability and predictable outcomes. Options A, C, and D misrepresent the core purpose of mocks; stubs are primarily used for verification, not controlling responses directly.
What will I practice in "Mocks, Stubs, and Test Doubles Vocabulary"?
This is an API Contract Testing exercise set. It walks through 25 scenario-based multiple-choice questions built around real usage of API Contract Testing terminology that IT professionals encounter on the job.
Is this exercise free to use?
Yes. Every exercise on CoderSlingo, including this one, is free to complete with no account, sign-up, or paywall.
How many questions are in this exercise?
This set contains 25 questions. Each one shows immediate feedback and a detailed explanation after you answer, so you learn the correct usage right away rather than waiting for a final score.
Do I need prior experience to complete this exercise?
No prior experience is required. Each question includes a full explanation covering the reasoning behind the correct answer, so the exercise itself teaches the API Contract Testing vocabulary as you go.
Can I retry the exercise if I get questions wrong?
Yes — use the "Try again" button on the results screen to reset your answers and go through all the questions again. There is no limit on attempts.
Is my progress saved?
Your answers and score for the current session are tracked in the browser as you go. No account or login is needed, and there is nothing to install.
What if I don't understand a term used in a question?
Read the explanation shown after you answer each question — it breaks down the correct term in plain English with a real-world example. You can also check the site Glossary for quick definitions.
How is this different from reading a blog article on the topic?
Exercises like this one are interactive drills that test and reinforce specific vocabulary through multiple-choice questions, while blog articles explain concepts in prose. Practising here after reading builds active recall, not just passive recognition.
Where can I find more API Contract Testing exercises?
See the API Contract Testing exercises hub for the full set of related pages, or browse all exercise categories from the main Exercises index.
Can I use this exercise to prepare for a technical interview?
Yes — API Contract Testing vocabulary comes up often in technical discussions and interviews. Pair this exercise with our dedicated Interview Preparation section for role-specific practice.