Who Cares About Your Tests?
13 Sep 2024
Something that I’ve been pontificating on in my chamber as of late are the definitions of various types of tests that people often treat as fact. “Unit”, “integration”, “acceptance”, “end-to-end”—these are all terms that at various points in time I’ve heard very confident assertions on their true, implacable meaning.
What I’ve come to understand is that, in fact, there is no hermetically sealed, subterranean storehouse where a scientifically agreed upon “unit test” exists. I was surprised to find that none of these things are naturally occurring. They all have emerged from groups of people, trying to address problems that they had in some context.
To me, the most powerful part of practicing test-driven development is the act of embodying a hypothetical other. When we write a test, we are inhabiting a perspective separate from the programmer. Maybe it’s an end user, or maybe it’s another programmer in the future (maybe that’s us). We try our best to be empathetic to what they need from the given system under test.
I like the way that Kent Beck has occasionally used the term “programmer test” in place of “unit test”, or Brian Marick’s testing quadrant diagram that groups types of tests as “technology facing” or “business facing”. I feel that this is lost in arguments over definitions of these terms: who cares? If a test fails, what benefit does that provide? In the case of a mock-intensive unit test (which I’ve grown to abhor—not that I haven’t written lots of them), if a test simply tells me that the implementation details of some behavior have changed, is that helpful to me as the programmer who changed the code? Not really. I literally just changed it, so… thanks? Is it helpful to anyone else? I’m inclined to think not.
It’s not surprising to me that this more human-oriented aspect is often overlooked. The industry seems hellbent on refusing to learn that programming is a social activity, and would rather serve tools and practices than do the harder work of figuring out how those things could better serve human beings.
And I think I get it: working with people is tricky. We’re complicated, and seem to have new problems all the time. By comparison, working in absolutes is simple, and there’s comfort in that. But, truly, who cares? Here’s one of my favorite Martin Fowler quotes, talking about the term “unit” from his article on the term “Unit Test”:
“However you define it doesn’t really matter.”
Better stuff on this
- “Test Desiderata” from Kent Beck.
- A series of conversations between David Heinemeier Hansson, Kent Beck, and Martin Fowler on the subject “Is TDD Dead?”. (Seriously, watch at least the first part…)
- Ian Cooper’s talk: “TDD, Where Did It All Go Wrong?”.
- And last, but not least, Kent Beck’s “Test-Driven Development By Example”.