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

  1. 6.1 Test-first and the green step
  2. 6.2 When TDD fits, and characterizing legacy
  3. 6.3 BDD and shared language
  4. 6.4 Test structure and naming
  5. 6.5 Test levels and shapes
  6. 6.6 Contract, smoke and test scope
  7. 6.7 Test doubles and isolation
  8. 6.8 Test design techniques
  9. 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

  1. Why write the test before the code in TDD?

    1. Tests always run faster when they're written before the code they test
    2. Compilers refuse to build code unless its tests already exist first
    3. It clarifies behavior, proves the test can fail and drives testable design
    4. 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.

  2. What is a common criticism of strict TDD, and a fair response?

    1. TDD makes code impossible to deploy; teams should only use it for prototypes
    2. TDD forbids any refactoring; teams should refactor in a separate phase later
    3. It can feel slow for exploratory or UI work; apply it where logic is complex
    4. 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.

  3. What is behavior-driven development (BDD)?

    1. A testing approach that only checks the behavior of the UI
    2. TDD extended with shared business language, like Given/When/Then
    3. A debugging technique for stepping through code behavior
    4. 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.

  4. What is the "Arrange, Act, Assert" pattern?

    1. A Git branching model with separate branches for each test stage
    2. Structuring a test as setup, the action under test, and verification
    3. A deployment pipeline with arrange, act and assert stages in order
    4. 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.

  5. What is a unit test?

    1. A fast, isolated test of a small piece of code without real dependencies
    2. A test of the whole system that's driven entirely through the UI
    3. A test that measures the network's throughput between two servers
    4. 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.

  6. What is contract testing?

    1. Testing legal contracts for typos and missing clauses before they're signed
    2. Checking that a provider and its consumers agree on an API, without full systems
    3. Running a load test against an API that handles customer contracts
    4. 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.

  7. What is the difference between a mock and a stub?

    1. They're always identical, and the two terms are fully interchangeable
    2. A stub returns canned data; a mock also verifies how it was called
    3. A mock returns canned data, while a stub verifies how it was called
    4. 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.

  8. What is boundary value analysis?

    1. Testing edge values like 0, 1, max and max + 1, where bugs cluster
    2. Testing only the typical values that most users are likely to enter
    3. Testing the physical boundaries of the office's wireless network
    4. 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.

  9. What does code coverage measure, and what is its main limitation?

    1. How many bugs exist in the code; and it's always perfectly accurate
    2. How fast the tests run; but it ignores any tests that are slow
    3. The total number of tests; but it ignores which code they cover
    4. 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.

  10. In the green step of TDD, how much code should you write?

    1. The complete feature including future needs
    2. Just enough to make the failing test pass
    3. As much as possible in one go
    4. 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.

Practice all 261 questions

More Development Practices