Skip to main content
Fabien Fouassier
Back to Writing

What a Green Test Suite Cannot Tell You

A small booking example shows how examples, general rules and deliberate faults each catch different mistakes, and why none of them can choose the right behavior for you.

Topics
TestingQuality
Published
Reading time
5 min read

A passing test shows that one result matched one expectation. The useful question is what kind of mistake that expectation could have caught. A suite can run every line of code and still accept the wrong behavior, especially when its expected values copy the assumptions of the code they test.

I find it more useful to examine those blind spots than to debate whether unit tests are worthwhile in general. Consider working out how many places are left in a booking pool. It lets us compare three ways of testing the same thing without pretending that any of them proves a real product correct.

Start with the contract

The rules are simple. Capacity and requested places are whole numbers, never negative. If more places are requested than exist, none remain. Anything else is rejected, not quietly corrected. The calculation does not make reservations, handle two people booking at once, or decide whether overbooking should be allowed.

Those exclusions matter. Returning zero when too many places are requested is a choice made for this calculation. It is not a safe way to take bookings. A real reservation system needs separate decisions about who may book, how bookings are stored and what happens when requests collide, and testing the arithmetic says nothing about them.

The next three sections examine this one calculation in three ways: examples, general rules and deliberate faults (Figure 1).

Read each technique top to bottom: what goes in, what is checked and what it can catch.

Places left in a booking pool

Capacity minus requests, never below zero

Examples

Chosen input

12 places, 5 requested

Expected answer

7 places left

Catches a mistake in a chosen case.

General rules

Many inputs

Every case from 0 to 50

Relationship holds

Never more than capacity

Catches a case nobody picked.

Deliberate faults

Changed code

E.g. always answer zero

Does a check notice?

Run the same checks

Tests the tests. A rewrite with identical answers should still pass.

Figure 1. Three ways to examine the same calculation An illustrative example. A fault that is caught or that survives is not a mutation score, and none of the three techniques decides whether the behavior is the right one.

Examples make decisions visible

A weak test might check only that the result is never negative. A version that always answers zero would pass it. The statement is true, but it cannot tell a useful version from a broken one.

A handful of examples says much more. With twelve places, five requested leaves seven. None requested leaves twelve. Twelve requested leaves none, and twenty requested also leaves none. An empty pool with nothing requested stays empty. A negative request and a fractional request are both rejected.

Each example pins down one decision: partial use versus exhaustion, the exact boundary, over-subscription, and what counts as invalid input. They are readable enough for another engineer to challenge the contract itself. Should over-subscription be rejected instead? That conversation is worth more than adding arbitrary inputs to a rule nobody examined.

Examples remain a selection, though. They cannot say whether an input nobody chose breaks a relationship that should always hold.

General rules describe relationships

For any valid input, the places left should be between zero and the original capacity. Requesting one more place should never increase the number left. Requesting nothing should change nothing. Taking two batches should leave the same as taking their total at once.

These rules describe consequences of the contract without repeating the subtraction in every expected value. For a small exercise, I checked them by trying every combination of capacity, request and extra request from 0 to 50. That is exhaustive for those limits, not for every possible number. Generating inputs automatically could cover more ground and shrink a failure to a small counterexample. Boundary examples are still needed for the unsupported values and the edges of what is accepted.

A general rule also needs someone to decide it is desirable. Taking two batches adding up to one big batch would be wrong if a real product charged a fee per batch. A clever generator would only explore the wrong rule more thoroughly.

Deliberate faults test the tests

Mutation testing changes the code on purpose and asks whether the tests notice. A change that slips through is a question to investigate, not an automatic order to write another assertion.

For this example I swapped in four hand-written alternatives for the final calculation and ran the same checks:

AlternativeWhat the checks showed
Always answer zeroCaught by the five-requested example. "Never negative" alone would have accepted it.
Add the request instead of subtracting itCaught by the examples and by the "never more than capacity" rule.
Subtract without stopping at zeroCaught by the over-subscription example and the "never below zero" rule.
Answer zero early when the request is enoughNot caught, because it gives the same answers for every valid input.

These are four deliberate faults and one equivalent rewrite, not a run of a mutation tool and not a mutation score. The last one should survive. Catching it would mean asserting how the code is written rather than how it behaves. A real mutation tool tries many more changes systematically, but each survivor still needs a human to interpret it. It may reveal missing behavior, code that can never run, an equivalent rewrite or an unrealistic fault. A high score can also reflect a narrow set of changes. Neither a score nor line coverage tells you whether an important behavior was left out of the specification.

Spend effort where the uncertainty is

For a simple calculation, examples and a few general rules give cheap, useful feedback. For code that reads outside data, how it rejects bad input deserves direct attention. For a workflow that coordinates storage and retries, a correct unit test says little about running twice or failing halfway, so the evidence has to reach those interactions.

I would not add general-rule and mutation tooling to every small helper by default. Extra dependencies, longer runs and hard-to-read failures all cost maintenance. I use them where the range of inputs, the business consequence or the uncertainty justifies the extra questions they ask.

In practice the order is: state the behavior, pick examples that separate its decisions, find the relationships worth exploring, then introduce faults to test the tests. When all of that passes, one question remains: is this the right behavior? That decision belongs to the people responsible for the system.