The Test That Told Me What I Meant

I used to write the code first
and the tests later, if at all.

Tests felt like paperwork.
Proof, after the fact,
that the thing I’d already decided was done
was actually done.

Then one day I tried it backwards.

I wrote the test first —
before the function existed —
and something strange happened.

I couldn’t do it.

Not because it was hard to type.
Because I didn’t actually know
what “working” meant yet.
What should it return on empty input?
What counted as an error?
What was I really promising?

The test forced me to answer
before I wrote a single line.

And half the confusion I usually discovered
three hours into the code
showed up right there,
in the first thirty seconds,
while I was just trying to say
what I meant.

That’s when tests stopped being paperwork
and became thinking.

Now the test is where I figure out
what I’m building,
in plain, runnable terms,
before I get lost in how.

The comment I’d have written
would have drifted out of date by Friday.

The test just goes red
the moment I break my own promise.

It’s the only documentation I have
that refuses to lie to me.

– Serguey Asael Shinder

Leave a comment