Testing assesses software behavior against expectations, but line coverage alone does not establish correctness. Strong tests make the relevant business meaning, inputs, expected outputs, and invariants visible instead of merely confirming that a particular implementation path ran. Algebraic laws can turn a correctness claim into checks that remain meaningful as code changes. section 7.1 section 8.1.1
Data-oriented design makes this especially direct. A pure, deterministic function accepts data and returns data, so a test can construct an input, invoke the function, and assert the result in one place. Dependencies, clocks, API calls, side effects, and identity management otherwise add setup and mocks that can obscure the behavior under test. section 11.2
Testing an invoice rule
To test whether a good customer receives the full grace period, create an open standard invoice with a known due date, pass a GOOD rating and a date at the grace-period boundary, then assert that it is not past due. The test states the business rule through its data rather than through hidden environment configuration. section 11.2
Design tests as readable consumers of domain data:
- Keep all information relevant to an assertion visible in the test; make the link from inputs to expected result clear. section 11.8
- Model scenario lifecycles with types and values rather than encoding each branch in a long test name or mock setup. section 11.3.4
- For side-effecting code, represent system states as data and drive mocks from those states; test the domain outcome, not only branch execution. section 11.3.4
- Generate and transform fixtures as data, varying irrelevant attributes to expose hidden couplings and rarely exercised states. section 11.8
Listing 11.2 Tests are structured around inputs and outputs
class Example {
@Test
void goodCustomersGetTheMaximumGracePeriod() { #A
LocalDate dueOn = LocalDate.of(2027, 1, 1); #B
LocalDate currentDate = dueOn.plusDays(MAX_GRACE_PERIOD); #B
boolean result = InvoiceService.isPastDue(
new Invoice(new CustomerId("1"), STANDARD, OPEN, dueOn), #B
CustomerRating.GOOD, #B
currentDate #B
);
assertFalse(result, """ #C
Customers in good standing are not considered past
due as long as they're within the grace period.
""");
}
}A compact test shows the preferred shape: explicit invoice data, an explicit current date, one call, and an assertion phrased as a business expectation. section 11.2
Generated data extends example-based checks. A serialization round-trip can create many accounts, serialize and deserialize each one, and compare the result with the original. Increasing the generated count lets the same structure explore a handful of cases, large datasets, or service limits. Randomization is useful for finding unexpected states and dependency failures, not a substitute for choosing meaningful properties. section 11.5.3 section 11.5.4 section 11.8
Useful tests also teach the domain. They document which invariants must hold, why a case matters, and what behavior is protected from regression. Treat test code as production code: introduce types where they clarify meaning, parameterize helpers around values under test, and use comments to explain why rather than narrate mechanics. section 11.3 section 11.8


































































