← All writing
Evaluation · 5 min read · 30 Nov 2026

Evaluating a Model Is Not Testing Software

Software testing asks whether code does what it was told to do. Model evaluation asks whether a statistical guess generalises to the world. Confusing the two leads to false confidence.

Cover image for the article: Evaluating a Model Is Not Testing Software

Two kinds of correctness

When I test a piece of software, I am checking a deterministic claim. Given this input, the function must return that output, every single time. If I write a unit test for a function that adds two numbers, I know exactly what correct looks like before I run anything. The specification exists independently of the code. Testing is the act of confirming that the implementation matches a definition I already had in my head.

Evaluating a model is a different kind of activity, even though it can look superficially similar. There is no fixed specification for what the model should output on a new, unseen input, only a hope that it has learned a pattern that holds beyond the examples it was trained on. I am not confirming that the model matches a known answer for every case; I am estimating how well it will perform on cases I have never seen and never will see, based on a sample that I hope is representative.

This distinction sounds academic until you actually build something, at which point it becomes the single most important thing to get right. Software testing is about correctness against a specification. Model evaluation is about generalisation under uncertainty. Treating the second as if it were the first is one of the most common and costly mistakes in applied machine learning.

A worked example: the spam filter

Suppose I build a spam classifier and write a test that feeds it ten emails I personally labelled as spam or not spam, then asserts that the model's predictions match my labels exactly. If all ten pass, have I proven the model works? In the software testing sense, yes: the code produced the expected output for those ten specific inputs. In the evaluation sense, I have learned almost nothing, because those ten emails might share quirks, such as a particular sender domain or phrasing, that do not represent the wider stream of emails the model will actually face.

Now imagine I instead hold out a thousand emails that the model never saw during training, and measure accuracy, precision and recall on that set. Say the model gets 94 percent accuracy. That number is not a pass or fail in the way a unit test is. It is an estimate, with an implicit margin of error, of how the model will perform on the population those thousand emails were drawn from. If tomorrow's spam uses new tactics that were not present in the data, that 94 percent tells me little about tomorrow.

Here is the part that trips people up most often: if any of those thousand held-out emails resembles something the model saw during training, even indirectly, for example if the same newsletter template appears in both the training set and the test set under slightly different wording, the 94 percent is inflated. This is leakage, and it is the evaluation equivalent of writing a unit test that checks the function against the exact same inputs used to write the function in the first place. The test passes, but it tells you nothing about the thing you actually care about.

A software test with leakage simply does not exist as a concept, because the specification is fixed and known in advance. A model evaluation with leakage looks identical to a clean one on paper, same code, same metric, same reported number, but it is measuring something false. That is what makes evaluation harder than testing: a broken evaluation often shows no symptoms at all.

laptop screen showing confusion matrix

Why the difference matters in practice

Because a unit test either passes or fails, failure is loud and immediate. A broken evaluation is quiet. The 94 percent accuracy figure will sit in a report looking perfectly respectable, cited in meetings, used to justify deployment, right up until the model meets genuinely new data and performs far worse. There is no red cross in a test runner to warn you. The only defence is discipline in how the evaluation was constructed in the first place: a split that respects time if the data is temporal, respects grouping if examples cluster by sender or user or document, and never lets information from the test portion touch any decision made during training, including feature selection or hyperparameter tuning.

Another consequence is that a single number from an evaluation is never as final as a single passing test. Reporting 94 percent accuracy without a sense of variance across different random splits, or without a comparison to a sensible baseline such as always predicting the majority class, invites false confidence. If 90 percent of emails in the dataset are not spam, a model that predicts not spam every single time also scores 90 percent accuracy while doing no useful work whatsoever. A software test has no equivalent trap, because there is no majority-class baseline for addition; two plus two is either four or the test fails.

This is why I treat model evaluation as closer to an experiment in empirical science than to a verification step in engineering. It needs a control, a sense of what a naive baseline achieves, an honest accounting of how the data was split, and scepticism about any number that looks too good. Software testing, by contrast, is closer to proof: run it enough times under the same conditions and the answer will not change, because there is nothing to generalise to.

The practical takeaway

None of this means software testing is less valuable. The two activities are complementary and both matter. The code around a model, the pipeline that loads data, applies preprocessing, calls the model and formats the output, absolutely should be covered by conventional tests, because that code does have a fixed specification and bugs there are exactly the deterministic kind that unit tests catch well.

But the model's predictive behaviour itself cannot be verified the same way. It can only be estimated, with a methodology that guards against leakage, compares against honest baselines, and treats every reported metric as a claim about an unseen future rather than a fact about the present. The next time a single accuracy figure is presented as proof that a model works, the right question is not whether the number is high, but whether the process that produced it could generalise to data it has genuinely never touched.

email inbox spam folder
← All writing See the project case studies →