Ch. 22

Software Testing interview questions & answers

Writing tests that catch real bugs: unit versus integration scope, mocks and fakes, flaky-test diagnosis, boundary values, contract tests and deterministic async code.

8 interview questions11 quiz questions29 notes
your progress0%

Notes in this chapter

Filter all notes →
read ✓Software Testing · hard

Testing Time with an Injected Clock

Pass a clock into time-dependent code, test expiry boundaries to the millisecond with node:test, and see why sleep-based tests flake.

~7 min readread →
read ✓Software Testing · mid

Code Coverage and Its Limits

See a 100% covered function ship a boundary bug, read line and branch numbers from Node's coverage report, and set thresholds that help.

~6 min readread →
read ✓Software Testing · hard

Scoping End-to-End Tests

Choose which user journeys deserve browser-level tests, push the rest down the stack, and keep the E2E suite small, stable and owned.

~7 min readread →
read ✓Software Testing · mid

Testing Error Paths

Test failure cases on purpose: assert the exact exception and message, probe edge inputs like NaN, and check that failures leave no damage.

~7 min readread →
read ✓Software Testing · mid

Unit and Integration Test Balance

Watch fast unit tests pass while a real SQLite test catches a swapped column and an untranslated unique-constraint error, then split the work.

~7 min readread →
read ✓Software Testing · hard

Parallel Test Isolation

Reproduce a shared temp file, a fixed port and module-level state breaking parallel node:test runs, then give each test its own resources.

~7 min readread →
read ✓Software Testing · mid

Red, Green, Refactor

A real TDD session in Python's unittest: watch each test fail for the right reason, pass with minimal code, then refactor safely under green.

~6 min readread →
read ✓Software Testing · mid

Snapshot Tests Worth Reviewing

Use node:test snapshots on a receipt, see a diff where a real bug hides among cosmetic changes, and keep snapshots small and readable.

~6 min readread →
read ✓Software Testing · mid

Test Data Builders and Object Mothers

Replace sprawling inline fixtures with a test data builder in Python, compare it with an object mother, and avoid the mystery-guest default.

~7 min readread →
read ✓Software Testing · mid

Accessibility Tests Beyond Automated Scans

A hand-built modal passed axe with zero violations, then failed four keyboard and dialog checks in Playwright; a native dialog passed all five.

~7 min readread →
read ✓Software Testing · easy

Arrange, Act and Assert for Clear Tests

Split each test into arrange, act and assert so a failure names one broken behavior, shown on an order-cancellation service with node:test.

~7 min readread →
read ✓Software Testing · mid

Async Tests and Controlled Completion Order

Replace sleeps with deferred promises so an async test decides which response lands first, catching stale-result races on every run.

~7 min readread →
read ✓Software Testing · easy

Boundary-Value Tests and Off-By-One Errors

Test just below, at and just above every limit: a cart cap with a < that should be <=, plus a 50.00 threshold that floats quietly miss.

~6 min readread →
read ✓Software Testing · mid

Contract Testing Across Independent Services

Consumer-driven contracts in practice: a shipping service records what it needs from orders, and a renamed field fails before deploy.

~7 min readread →
read ✓Software Testing · mid

Fake Timers and Clock-Based Behavior

Test debounces, cooldowns and retry backoff with node:test mock timers, and avoid the Date.now and promise traps that make fake clocks lie.

~7 min readread →
read ✓Software Testing · mid

Test Fixtures and Independent State

A shared SQLite fixture makes tests pass alone and fail together; fix it with fresh state per test, commit-proof rollbacks and addCleanup.

~7 min readread →
read ✓Software Testing · mid

Flaky Tests and Root-Cause Evidence

Diagnose flaky tests with evidence: measure the failure rate, compare a test alone and in the suite, and replace sleeps that fail 23 runs in 100.

~7 min readread →
read ✓Software Testing · mid

Mocks, Stubs and Fakes: Dependency Test Choices

When to reach for a stub, a mock or a fake, shown on a password-reset service, plus a contract test that caught a fake more lenient than SQLite.

~7 min readread →
read ✓Software Testing · mid

Mutation Testing and Assertion Strength

Stryker plants small bugs in code to see if tests notice: a shipping rule with 100% line coverage scored 72.73% until boundary tests went in.

~6 min readread →
read ✓Software Testing · hard

Performance Tests and Realistic Workloads

Ramp load on a service with a 4-connection pool: throughput levels off near 190 req/s, and a fixed 300 req/s arrival rate ends in 85% timeouts.

~7 min readread →
read ✓Software Testing · hard

Regression Tests and Change Risk

Write a regression test that fails for the original bug, select tests from the diff, and see when an import graph misses the one that breaks.

~6 min readread →
read ✓Software Testing · hard

Security Tests for Rejected Operations

Test what each user must not do: a table-driven access matrix for an invoice API catches a missing ownership check that happy paths miss.

~7 min readread →
read ✓Software Testing · hard

Test Reports and Honest Coverage Claims

A green run with a skipped Stripe test and coverage that drops from 72.88% to 55.17% once test files are excluded: how to report what really ran.

~6 min readread →
read ✓Software Testing · hard

Visual Regression Tests and Stable Comparisons

Screenshot tests with Playwright: freeze the clock and viewport, and see why a 2% tolerance that hides a timestamp lets a wrong price through.

~7 min readread →

8 Software Testing interview questions study by subtopic

8 questions
  1. 1.How would you test a checkout flow?mid

    I would start with risks: wrong totals, duplicate orders, inventory changes and payment failures. Unit tests cover pricing rules and boundary values. Integration tests cover persistence, service contracts and idempotency. A small set of end-to-end tests covers important customer journeys with controlled test data. I would include timeout and retry scenarios, verify observable outcomes and avoid using real payment details. The goal is confidence in behavior, not merely a coverage percentage.

    What interviewers listen for
    • Prioritize business risks
    • Use multiple test levels
    • Cover failure paths and boundaries
    • Keep data and dependencies controlled

    Likely follow-up: How would you test a successful payment followed by a failed response?

  2. 2.How do you investigate a flaky test?mid

    First capture the failing seed, logs, environment and execution order. I would look for shared mutable data, real network dependencies, wall-clock assumptions and asynchronous work that the test does not await. Reproduce with repetition and isolation, then replace arbitrary sleeps with observable readiness conditions. Control clocks and randomness when appropriate. Temporary quarantine may protect delivery, but it should have an owner and a tracked fix rather than silently hiding a regression.

    What interviewers listen for
    • Capture failure evidence
    • Inspect timing and shared state
    • Wait for observable conditions
    • Track the underlying fix

    Likely follow-up: Why can retrying every failed test conceal defects?

  3. 3.When should you use a mock instead of a real dependency?mid

    Use a test double when the dependency is slow, costly, nondeterministic or difficult to drive into a failure state. A stub provides canned responses, while a mock can verify interactions. Prefer assertions on observable behavior unless the interaction itself is the contract. Too many mocks can reproduce implementation details and miss real incompatibilities, so complement isolated tests with integration or contract checks using realistic boundaries.

    What interviewers listen for
    • Control external dependencies
    • Distinguish stubs from interaction checks
    • Assert behavior
    • Complement doubles with integration tests

    Likely follow-up: What can an in-memory database hide compared with production?

  4. 4.What would you include in API contract tests?mid

    Check the observable agreement between consumer and provider: required fields, types, status codes, headers and relevant error formats. Include missing or optional data and compatibility expectations. Avoid asserting undocumented incidental ordering or internal implementation details. Run provider verification against the expectations consumers actually rely on. Contract tests help catch incompatible changes, but they do not replace full integration checks for authentication, networking or real data behavior.

    What interviewers listen for
    • Test the observable interface
    • Include success and error shapes
    • Make compatibility expectations explicit
    • Complement contracts with integration coverage

    Likely follow-up: How would you evolve a response without breaking existing clients?

  5. 5.How do you write reliable tests for asynchronous code?mid

    Await the operation and ensure the test runner observes rejected promises or callback failures. Control external dependencies and wait for a meaningful state change rather than an arbitrary sleep. For time-based behavior, a controlled clock can make tests fast and deterministic, but account for how the runtime schedules pending work. Include success, failure and cancellation where relevant. Clean up timers, listeners and background work so they do not affect later tests.

    What interviewers listen for
    • Await completion and propagate failures
    • Wait for observable state
    • Control time and external dependencies
    • Clean up background work

    Likely follow-up: How can a test accidentally pass before an asynchronous assertion runs?

  6. 6.How would you turn a production bug report into a regression test?easy

    Gather the relevant input, expected outcome and actual behavior, then reproduce the failure in a controlled environment. Reduce it to the smallest case that still shows the defect. Write a test at the lowest useful boundary that captures the broken behavior, and verify that it fails before the fix. After the change, confirm it passes and consider nearby edge cases. Remove sensitive production details from fixtures while preserving the properties needed to reproduce the issue.

    What interviewers listen for
    • Capture expected and actual behavior
    • Minimize the reproducer
    • Observe failure before the fix
    • Protect sensitive data and check nearby cases

    Likely follow-up: When would you need an integration test rather than a unit test?

  7. 7.How would you design a useful performance test for an API?hard

    Start with a workload model: request mix, arrival rate, payloads and data size. Set explicit latency and error-rate objectives and include warmup and steady-state periods. Observe tail latency, throughput, saturation and dependency behavior rather than only averages. Ensure the load generator is not the bottleneck. Separate normal-load validation from stress testing, and document environment differences so results are interpreted correctly. Repeat measurements to distinguish changes from noise.

    What interviewers listen for
    • Model representative traffic and data
    • Set latency and error objectives
    • Measure tail latency and saturation
    • Validate the generator and environment

    Likely follow-up: Why can average latency hide a serious user experience problem?

  8. 8.If time is limited before a release, how would you prioritize testing?mid

    Identify what changed, the user journeys affected and the consequences of failure. Prioritize high-impact paths such as access control, data integrity and core transactions, including important failure cases. Reuse reliable automated checks and target exploratory testing at uncertainty. Communicate what was covered, what remains untested and the residual risk to the release owner. Do not claim that a passing smoke suite proves the whole release is safe.

    What interviewers listen for
    • Use change impact and failure severity
    • Cover critical success and failure paths
    • Combine automation with targeted exploration
    • Communicate remaining uncertainty

    Likely follow-up: How would a change to a shared library alter your priorities?

Prefer multiple choice? All 11 Software Testing MCQs with answers →

esc