skip to content

Testing

Testing fundamentals with no framework in sight: what each level buys you, what a double stands in for, how cases get chosen, and what coverage really measures. Interviewers start here.

on this pageshow

explore

questions

85 · 5 sections

What is acceptance testing, and what decides whether a change passes it?

level: juniorimportance: must knowfreq 74%
basics
~20 s

Acceptance testing judges a change against the stated acceptance criteria of the requirement it implements, not against the shape of the code. It passes when every criterion is demonstrably met, and those criteria are agreed before the work starts.

open as a page

In a consumer-driven contract test, what does the recorded contract assert about the provider, and what does it deliberately not check?

level: juniorimportance: must knowfreq 42%
basics
~20 s

A consumer-driven contract records the requests one consumer sends and the response parts it actually reads, then asserts the provider can still produce them. It checks the shape of the boundary, not whether the provider's answers are correct.

open as a page

What makes a test end-to-end rather than a narrower test, and what does it prove?

level: juniorimportance: must knowfreq 78%
basics
~20 s

An end-to-end test drives the fully assembled, deployed system through a real entry point, with nothing inside the system replaced by a stand-in, and checks the observable outcome of a complete journey rather than any internal call or state.

open as a page

What defects does an integration test against a real dependency catch that a fully mocked test cannot?

level: juniorimportance: must knowfreq 74%
basics
~20 s

Integration tests catch defects that live in the boundary itself: wiring and configuration, serialization, schema and type mapping, and real query behaviour. A programmed double returns what you assumed, so it can never contradict that assumption.

open as a page

What is the test pyramid, and why are narrow unit tests the widest layer?

level: juniorimportance: must knowfreq 78%
basics
~20 s

The test pyramid is a shape guideline for an automated suite: many fast, narrow unit tests at the base, fewer tests across a real boundary above them, and a thin end-to-end layer on top. Width means test count.

open as a page

Which collaborators in a unit test earn a stand-in, and which should be left real?

level: juniorimportance: must knowfreq 72%
basics
~20 s

Replace collaborators that cross a process boundary, are slow, or are nondeterministic, such as remote services, queues and clocks. Leave value objects, pure calculations and cheap in-process helpers real, because replacing those deletes the behaviour the test exists to check.

open as a page

What are the five kinds of test double in Meszaros's taxonomy, and what separates them?

level: juniorimportance: must knowfreq 74%
basics
~20 s

A dummy is passed but never used. A fake has a working lightweight implementation. A stub returns canned answers. A spy records the calls it received. A mock holds expectations and fails the test itself when they are not met.

open as a page

What is interaction verification in a unit test, and how does it differ from asserting on returned state?

level: juniorimportance: must knowfreq 70%
basics
~20 s

Interaction verification asserts how the unit called its collaborators - which method, how often, with which arguments. State verification only checks what came back or the state afterwards. Use interaction checks when the effect leaves nothing to return.

open as a page

What is stubbing a collaborator's method in a unit test, and why do it?

level: juniorimportance: must knowfreq 72%
basics
~10 s

Stubbing replaces a collaborator's method with a canned answer the test chose in advance. The unit under test then runs down a known path, without depending on the real dependency's data, speed or availability.

open as a page

In the test-double taxonomy, how does a stub differ from a mock?

level: middleimportance: must knowfreq 68%
basics
~20 s

A stub supplies canned answers so the code under test can run; it can never fail a test. A mock is configured in advance with the calls it must receive and fails the test itself when the run does not match.

open as a page

What are the three phases of the Arrange-Act-Assert test structure?

level: juniorimportance: must knowfreq 78%
basics
~20 s

Arrange builds the fixture, inputs and collaborators the test needs. Act invokes the one behaviour under test and captures its result. Assert compares that outcome with the expected one. Given-When-Then names the same three phases.

open as a page

What is a flaky test, and why is it worse than a test that fails every time?

level: juniorimportance: must knowfreq 78%
basics
~20 s

A flaky test gives different verdicts on unchanged code, passing on one run and failing on the next. A consistent failure names a real problem; a flaky one teaches the team to re-run instead of investigate, destroying the suite's signal.

open as a page

What makes a test independent of the other tests in its suite?

level: juniorimportance: must knowfreq 78%
basics
~20 s

An independent test arranges everything it needs itself, writes to no state another test can observe, and leaves the environment as it found it. It gives the same verdict alone, in any position in the run, or beside tests on another worker.

open as a page

What is the assertion roulette test smell, and what refactoring removes it?

level: juniorimportance: must knowfreq 58%
basics
~20 s

Assertion roulette is a test carrying many unnamed assertions, so a failure reports only a line number and you must guess which check broke. Remove it by naming each assertion or splitting the test so one behaviour gets one test.

open as a page

What are the most common causes of a test that fails intermittently on unchanged code?

level: middleimportance: must knowfreq 68%
basics
~20 s

The usual families are timing assumptions, concurrency races, uncontrolled inputs such as the real clock, time zone or random values, calls to real external systems, dependence on the order cases run in, and state leaked between cases.

open as a page

In boundary value analysis, which values do you test for a field that accepts 1 through 60?

level: juniorimportance: must knowfreq 82%
basics
~20 s

Test the edges, not the middle: 0 and 1 low, 60 and 61 high. Defects hide where a comparison flips from accept to reject, so each limit gets a value on it and one just past.

open as a page

What is a decision table in test design, and what does each column represent?

level: juniorimportance: must knowfreq 66%
basics
~20 s

A decision table is a grid whose rows list the conditions of a rule set and the actions they produce. Each column is one rule: one combination of condition outcomes plus the actions it triggers. Each surviving rule becomes one test case.

open as a page

What is equivalence partitioning, and how do you pick the value you test from each class?

level: juniorimportance: must knowfreq 78%
basics
~20 s

Equivalence partitioning splits the input domain into classes the software is specified to handle identically, then tests one representative from each valid and each invalid class. If a class really is uniform, one value speaks for all of it.

open as a page

What is pairwise (all-pairs) test design, and why is it so much smaller than the full cross-product?

level: juniorimportance: must knowfreq 68%
basics
~20 s

Pairwise test design picks a small set of configurations in which every pair of values from two different parameters appears together at least once. It is tiny compared with the full cross-product because a single row covers many pairs simultaneously.

open as a page

What are states, events, guards and transitions in a state transition model?

level: juniorimportance: must knowfreq 66%
basics
~20 s

A state is a condition the system rests in between inputs. An event is an incoming trigger. A guard is a condition that must hold for that trigger to fire. A transition is the resulting move plus any action it performs.

open as a page

What is an approval test, and how does it differ from a test with hand-written assertions?

level: juniorimportance: must knowfreq 46%
basics
~20 s

An approval test runs the code, writes the output to a received artefact, and compares it against a previously approved artefact. Nobody types the expected value: a human reviews the output once and approves it, and the test then guards that exact output.

open as a page

What is the difference between line coverage and branch coverage in a test run?

level: juniorimportance: must knowfreq 84%
basics
~20 s

Line coverage counts source lines executed at least once. Branch coverage counts which outcomes of each decision were taken, the true side and the false side. A line can execute while one of its two outcomes never runs.

open as a page

Can a test suite with no assertions reach 100% line coverage, and what does that prove?

level: juniorimportance: must knowfreq 76%
basics
~20 s

Yes. Coverage instrumentation records which code the tests executed, not whether anything checked the result. A suite that calls every function and asserts nothing still reports 100%, and proves only that the code runs without crashing.

open as a page

What is mutation testing, and what does a surviving mutant tell you about a suite?

level: juniorimportance: must knowfreq 45%
basics
~20 s

Mutation testing seeds small deliberate faults into the code and reruns the tests. A fault the tests catch is a killed mutant; one no test notices survives, showing that code is executed but never actually asserted on.

open as a page

Why must an approval test normalise timestamps and generated ids before comparing output?

level: middleimportance: must knowfreq 41%
basics
~20 s

Because values that change every run make the received artefact differ from the approved one even when the code has not changed. The test then fails nondeterministically, so teams re-approve reflexively and the approval stops meaning anything.

open as a page