Testing Patterns & TDD Vocabulary
5 exercises — mock/stub/spy/fake/dummy test doubles, TDD red-green-refactor discipline, property-based testing, diagnosing flaky tests, and consumer-driven contract testing with Pact.
Dummy
Passed as an argument but never actually used in the test. Just fills a required parameter.
Example:
new UserService(logger = NullLogger()) — the test doesn't care about logging.Stub
Returns hard-coded or pre-configured answers. Does NOT verify how it was called.
Example:
userRepo.findById.returns(testUser) — control input to the unit under test.Use when: you want to control indirect inputs (return values, exceptions thrown).
Mock
Pre-programmed with expectations. Verifies that the expected calls were made with the expected arguments.
Example:
emailService.expects("sendWelcomeEmail").with(user).once()Use when: the test is verifying that the system under test called a collaborator correctly.
Failure mode: test fails at mock.verify() if expectations were not met.
Spy
Like a mock but set up after the call. Records what happened without pre-setting expectations.
Example:
const spy = jest.spyOn(emailService, "send"); // assert afterUse when: you want to observe calls to a real object without completely replacing it.
Fake
A working, simplified implementation of a real dependency.
Examples: in-memory SQLite database (instead of PostgreSQL), in-memory message broker, test SMTP server.
Use when: integration-level tests need a fast real-like implementation.
Rule of thumb:
• "Don't mock what you don't own" — only mock collaborators you control
• Over-mocking leads to tests that pass but don't test real behavior
• Prefer stubs/fakes for infrastructure; prefer mocks for verifying key interactions
Vocabulary:
• test double — umbrella term for any stand-in for a production object
• system under test (SUT) — the class or function being tested
• collaborator — objects or services the SUT interacts with
• indirect input — data supplied to the SUT through a collaborator
• indirect output — side effects or calls the SUT makes to a collaborator
Frequently Asked Questions
What does the "Testing Patterns & TDD Vocabulary" vocabulary exercise cover?
This exercise tests real IT vocabulary related to testing patterns & tdd vocabulary through 10 multiple-choice questions, each built from realistic workplace sentences rather than abstract definitions.
Is this vocabulary exercise free to use?
Yes. Every exercise on CoderSlingo, including this one, is completely free — no account, sign-up, or payment required.
How many questions does this exercise have?
This exercise has 10 questions. Each one shows a real-world sentence or scenario with multiple-choice options and an explanation once you answer.
What happens after I answer a question?
You'll see immediate feedback showing whether your answer was correct, along with a short explanation of why — then a button to move to the next question, and a full results screen at the end.
Can I retry the exercise if I get questions wrong?
Yes. Once you reach the results screen, click "Try again" to reset your answers and go through the exercise from the start as many times as you like.
Do I need to create an account to take this exercise?
No account is needed. Your answers are scored in your browser during the session — nothing is saved to a server, so you can jump straight in.
Is my progress saved if I leave the page?
No — progress within an exercise resets if you navigate away or reload. Each exercise is short enough to complete in a few minutes in one sitting.
Are these vocabulary exercises connected to other topics?
Yes — this module shares real-world context with 2 other vocabulary modules. See "Related vocabulary" below to keep building a connected skill set.
How is this different from reading a glossary or blog article?
Exercises like this one are active recall drills — you have to choose the correct term or phrasing yourself, which builds retention faster than passively reading a definition.
Where can I find more vocabulary exercises?
Browse the full Vocabulary exercises hub for hundreds of modules covering Agile, DevOps, security, databases, architecture, and more — organised by IT role and skill.