
A test can fail for two very different reasons. The program might no longer produce an outcome that its users depend on, or the program might produce exactly the same outcome through a different sequence of internal steps. The first failure is useful evidence. The second may indicate that the test describes implementation details rather than the real promise of the program. Tests ought to help maintainers decide whether changes are safe, so it is worth identifying which kind of promise each test is intended to protect.
Decide what counts as an observable result
A price-formatting function provides a manageable example. Given an integer amount in the smallest currency unit and a language setting, it returns a string for a product card. Internally, the formatter might separate digits, choose a decimal marker and insert a symbol. The user does not depend on three operations happening in that order. The user depends on seeing a correctly formatted amount. An acceptance example can specify the amount and settings, followed by the exact expected string. It does not need a substitute for every private helper.
Observable behavior is not limited to text returned by a pure function. An operation that creates a record may promise that a subsequent lookup finds that record. A print operation might generate a file containing the requested content. A failed operation might leave existing data unchanged. These effects are valid subjects for tests because some other part of the system depends on them. Identify the promise first, then choose a way to observe it. Do not settle immediately for the easiest internal variable to inspect.
Build examples around relevant distinctions
The first formatting example might show that an ordinary amount produces a recognizable value. The next step is to cover distinctions that change the result. Zero is a real amount, not evidence that a price is absent. An undefined price may require a separate message. Very large amounts may need digit grouping. Negative amounts might be valid in a refund workflow but invalid for an ordinary product price. The correct treatment of these conditions depends on the application, and a well-chosen test makes that dependency explicit.
Be careful about interpreting every possible variation as a separate behavioral requirement. A particular calculation may follow the same rule for thousands of amounts. A few examples on both sides of its meaningful boundaries can be more revealing than a deeply repetitive list of ordinary values. For instance, if grouping changes when an amount reaches a certain digit count, test a value just below that point and one at the point. Select test values because they exercise a rule or reveal uncertainty, not simply because they expand the number of cases.
Verify the agreement between components
Related reading: Creating a test set for language model outputs.
A correctly formatted string does not guarantee that the catalog displays it correctly. The catalog might supply the wrong amount or interpret a missing price as zero before calling the formatter. A test focused on the formatting rule is still valuable. It provides fast, precise feedback when that rule breaks. A broader check for a product card can establish another promise: given a record with known values, the displayed card contains the appropriate price. Both test levels are useful when each guards a distinct kind of behavior.
Errors at integration boundaries can arise even when every isolated component appears to behave correctly. A response adapter might convert a numeric amount to a string, which the receiving component treats differently. A storage operation might represent missing values using a different convention from the view. When a test replaces every collaborator with a convenient artificial result, those disagreements remain invisible. Reserve at least a few representative checks for real interactions between components whose assumptions may differ. They can remain small enough to run routinely.
Know when an interaction is part of the contract
Some behavior genuinely consists of an interaction. A notification operation that accepts a saved record might be required to schedule exactly one corresponding message. A repeated submission might be expected to retrieve the existing result instead of creating additional work. In such cases, verifying the interaction with a collaborator can be appropriate. The collaborator is observing a responsibility that the program explicitly promises. This is different from asserting that a private formatting helper was called twice, merely because the current implementation happens to use it.

The distinction is particularly important with test substitutes. A substitute may return known data, record a meaningful request or simulate an unavailable dependency. These are useful ways to control conditions that a test otherwise cannot reproduce easily. But a substitute that insists on an elaborate sequence of private calls can turn the test into a second copy of the original algorithm. A refactor then requires updating both copies, even though the user-visible behavior has not changed. The cost is maintenance without corresponding protection.
Provide diagnoses without revealing internal choreography
Behavior-based tests need not be vague. Instead of checking whether an operation produced any text at all, compare the result with the intended value and give the example a meaningful name. A failure should state the relevant input, the expected result and the actual result. If the operation writes state, inspect the fields that establish whether its promise succeeded. Avoid asserting every field in a large generated object unless every field matters to the consumer. Such comparisons can make harmless additions look like failures.
Similarly, one large test that verifies an entire journey may be hard to diagnose when it fails halfway through. Use narrower tests for the underlying rules and a representative workflow to establish that the parts agree. The workflow test can focus on the outcome of the complete operation rather than restating all the checks already made at the smaller level. A good arrangement provides enough context to locate a meaningful failure without requiring an exhaustive collection of fragile end-to-end scenarios.
Run a deliberate refactoring experiment
A useful exercise is to make a small behavior-preserving change. Return to the price formatter and combine two internal functions, or replace repeated conditions with a concise equivalent expression. Keep the input and output contract intact. Run the existing tests. If a formatting example fails because the result has changed, inspect the difference: the refactor may not be correct. If a test fails because an old private helper no longer exists, decide whether its invocation was ever a meaningful promise. Rewrite the latter test around the actual contract when appropriate.
Do not discard every test that fails during structural changes. A test may protect a side effect that was missed in the initial understanding of the program. For example, an operation might preserve the order of entries in an exported list because another system reads them in that order. The internal cause of the order is incidental, but the order itself can be contractual. Clarify the reason for each failure before changing the test. A test suite should not be weakened just to make a patch appear successful.
Keep tests legible to the people changing the application
Tests often become the clearest surviving explanation of an application rule. A developer may encounter an example specifying that an absent price produces a neutral placeholder, whereas an explicit zero produces a formatted zero. Even without reading the original feature discussion, the example shows a meaningful distinction. Preserve that readability by giving examples concise names, keeping important input values visible and avoiding large generic fixtures that conceal which field triggers the result. Helpers can reduce repetitive setup when they do not hide the actual scenario.
Review the suite as a description of behavior, not as a collection of lines that need to execute. Ask what promises would be lost if each test were removed. If many tests establish the identical promise through slightly different private paths, consolidate them carefully. If an important condition has no corresponding example, add one. The aim is a suite in which failures help explain real changes and successes support confidence in stated requirements. That makes testing a tool for preserving useful flexibility rather than an obstacle to improving the implementation.
Explore the implementation area: Backend development.


