TDD and the Testing Pyramid Interview Questions
261 multiple-choice tech interview questions on TDD and the Testing Pyramid: test-first practice and the green step, when TDD fits and characterizing legacy, BDD and shared language, test structure and naming, test levels and shapes, contract and smoke tests, test doubles and isolation, test design techniques, and coverage, mutation, flakes and testing in production. Written for technical phone screens and interview prep, organized by subtopic, with a short explanation for every answer. Learn the 39 key terms with the flashcards first, then test yourself.
Take the practice test · Flashcards · All study tools
What it covers
- 6.1 Test-first and the green step
- 6.2 When TDD fits, and characterizing legacy
- 6.3 BDD and shared language
- 6.4 Test structure and naming
- 6.5 Test levels and shapes
- 6.6 Contract, smoke and test scope
- 6.7 Test doubles and isolation
- 6.8 Test design techniques
- 6.9 Quality signals and production
Key terms
6.1 Test-first and the green step
- TDD
- Red-green-refactor: test first, minimal code, then improve design
- BDD
- Behavior described as Given/When/Then scenarios in shared language
- Arrange-Act-Assert
- Three-part structure for a test
6.5 Test levels and shapes
- Testing pyramid
- Many unit tests, fewer integration tests, few E2E tests
- Contract testing
- Verifying provider and consumer agree on an API contract
6.7 Test doubles and isolation
- Mock
- Test double that verifies how it was called
- Stub
- Test double returning canned responses
- Boundary value analysis
- Testing at the edges of input ranges
6.9 Quality signals and production
- Flaky test
- Test that passes and fails without code changes
- Mutation testing
- Seeding code changes to see whether tests catch them
- Dummy
- A unused placeholder passed only to satisfy an argument or constructor
- Ice cream cone
- An inverted mix of mostly manual and end-to-end tests, with few fast checks
- Equivalence partitioning
- Grouping inputs that should behave alike and testing a representative of each group
- Property-based testing
- Stating a rule that should hold for many generated inputs and hunting counterexamples
- Smoke test
- A short, shallow check that a build or deploy is basically alive
- London school
- A TDD style that isolates a unit and checks its interactions with neighbors
- Chicago school
- A TDD style that prefers sociable objects and state-based results
- Approval test
- A check that compares current output to a previously accepted snapshot
- Test smell
- A sign a test is hard to understand, brittle, or untrustworthy
- Regression testing
- Re-running checks after a change to see that existing behavior still holds
- Ping-pong TDD
- A pairing style where one partner writes a failing test and the other makes it pass
- Mystery guest
- Hidden setup or data that a test depends on but does not show
- Assertion roulette
- Several unrelated asserts in one test, so a failure is hard to pinpoint
- Outside-in
- Starting from a failing customer-facing example and filling in the design beneath it
- Sociable unit test
- A focused test that uses real nearby objects and doubles only the awkward edges
- State verification
- Checking a result or visible state after the behavior runs
- Interaction verification
- Checking that a collaborator received particular calls
- Decision table
- A grid of conditions and actions used to find missing or conflicting cases
- Pairwise testing
- Covering every pair of parameter values instead of every full combination
- Equivalent mutant
- A seeded change that does not alter observable behavior, so no test should fail
- Test isolation
- Each test can run alone, in any order, without leftover state from others
- Test list
- A running inventory of examples still to write
- Living documentation
- Examples that stay executable so they remain honest as the system changes
- Shrinking
- Reducing a failing generated input to a smaller, clearer counterexample
- Metamorphic testing
- Checking known relations between outputs after a known change to the input
- Negative testing
- Checking that invalid input is rejected or handled in a defined way
- Build verification test
- A small automated check that an assembled artifact is worth promoting
- DAMP
- Preferring descriptive, meaningful tests even if that means some duplication
- No-op
- A collaborator implementation that does nothing, used when a side effect must not happen
Sample practice questions
Why write the test before the code in TDD?
- Tests always run faster when they're written before the code they test
- Compilers refuse to build code unless its tests already exist first
- It clarifies behavior, proves the test can fail and drives testable design
- Writing tests first removes any need to refactor the code later
Answer: C. It clarifies behavior, proves the test can fail and drives testable design A test that has never failed might not be testing anything.
What is a common criticism of strict TDD, and a fair response?
- TDD makes code impossible to deploy; teams should only use it for prototypes
- TDD forbids any refactoring; teams should refactor in a separate phase later
- It can feel slow for exploratory or UI work; apply it where logic is complex
- TDD requires 100% UI test coverage; teams should write E2E tests for everything
Answer: C. It can feel slow for exploratory or UI work; apply it where logic is complex Pragmatic teams choose test-first where it gives the most value.
What is behavior-driven development (BDD)?
- A testing approach that only checks the behavior of the UI
- TDD extended with shared business language, like Given/When/Then
- A debugging technique for stepping through code behavior
- A code formatting standard enforced by a linter in CI
Answer: B. TDD extended with shared business language, like Given/When/Then Tools such as SpecFlow's successor Reqnroll, Cucumber and Behave run Gherkin scenarios.
What is the "Arrange, Act, Assert" pattern?
- A Git branching model with separate branches for each test stage
- Structuring a test as setup, the action under test, and verification
- A deployment pipeline with arrange, act and assert stages in order
- An agile ceremony held at the start of each sprint to plan testing
Answer: B. Structuring a test as setup, the action under test, and verification Given/When/Then is the BDD equivalent.
What is a unit test?
- A fast, isolated test of a small piece of code without real dependencies
- A test of the whole system that's driven entirely through the UI
- A test that measures the network's throughput between two servers
- A manual test that's carried out by the customer before sign-off
Answer: A. A fast, isolated test of a small piece of code without real dependencies Unit tests should run in milliseconds and give precise failure locations.
What is contract testing?
- Testing legal contracts for typos and missing clauses before they're signed
- Checking that a provider and its consumers agree on an API, without full systems
- Running a load test against an API that handles customer contracts
- Testing only the database schemas, never the services that use them
Answer: B. Checking that a provider and its consumers agree on an API, without full systems Pact is a popular consumer-driven contract testing tool.
What is the difference between a mock and a stub?
- They're always identical, and the two terms are fully interchangeable
- A stub returns canned data; a mock also verifies how it was called
- A mock returns canned data, while a stub verifies how it was called
- Stubs are only ever used in production code, never inside tests
Answer: B. A stub returns canned data; a mock also verifies how it was called Fakes (simple working implementations) and spies are other test doubles.
What is boundary value analysis?
- Testing edge values like 0, 1, max and max + 1, where bugs cluster
- Testing only the typical values that most users are likely to enter
- Testing the physical boundaries of the office's wireless network
- Testing with randomly generated values from across the input range
Answer: A. Testing edge values like 0, 1, max and max + 1, where bugs cluster Off-by-one errors cluster at boundaries.
What does code coverage measure, and what is its main limitation?
- How many bugs exist in the code; and it's always perfectly accurate
- How fast the tests run; but it ignores any tests that are slow
- The total number of tests; but it ignores which code they cover
- Code executed by tests; high coverage doesn't prove the right checks
Answer: D. Code executed by tests; high coverage doesn't prove the right checks Assertions matter: a test without meaningful assertions still adds coverage.
In the green step of TDD, how much code should you write?
- The complete feature including future needs
- Just enough to make the failing test pass
- As much as possible in one go
- None; the test should pass on its own
Answer: B. Just enough to make the failing test pass Further behavior is driven by the next failing test.