TDD journeyfolk, let me rattle your cage a little this fine afternoon.
lemme sketch a common situation for me. i have a problem, not a small one, to be solved in a tech stack i’m not intimately familiar with. further, some aspects of the problem are things no one on stack overflow has ever done before. they look, on paper, like they might be doable, but there’s no drop-in and very little advice. i’m in this situation where i have to try something – anything – and fuss with it for a while to see if it might work.
let’s call this the desperate-ignorance mode of working. i am desperately ignorant of the code i’m about to try writing.
and here’s the rattle: get off me about writing some semi-end-to-end test in junit that will prove i understand my problem/solution pair.
it is very difficult to write a good preservable long-lived test of a thing whose syntax you don’t understand, and while it would be nice if i only ever had to work in areas where i have confidence that i even know enough to know what i want, i quite often don’t, due to my role in the team.
so take deep breaths, and give a little trust? dogma just does not help me.
i have been TDDing more than many have been aware what a computer was. i am a TDDer. i write microtests, i advocate them, i live by them. i am not going to ship code that doesn’t honor the geepaw guarantee. i don’t do that any more. i go faster with microtests. i choose them.
but it’s dogmatic and foolish to ask me to roll a test for a thing whose most basic mechanism i don’t understand, even from a blackbox view. i don’t write tests because God told me too. i write tests because i know what i want and it gets me to that faster.
if i don’t know what i want, i can’t even sketch a test. when i barely know what i want, i can write a huge bad ugly test expensively, one that i don’t like and will throw out the very second i understand what i want.
but don’t get on me about whether i’m a TDDer. i am a TDDer. i won’t let anything stop me from background-working on getting to testability.
i just don’t do that.
“well, let’s write a test.” “ummm. a test for what? a test that this compiles? a test that i will like it?” i don’t work for the tests. the tests work for me.
i already have a test that it compiles, it’s called “the compiler”. and i already have a test that i will like it, it’s called “me”. and they’re very fast, very cheap, and very reliable.
when i know what i want my code to do, i will – believe me – learn how to write a test for that. when i know how to test my code, i will – believe me – write the damned test.
i feel folks still don’t understand that these heavy flickery largescale tests are of almost no use in real TDD. they’re hard as fuck to write, & they tell you nothing a run won’t immediately tell you, when you’re a stranger in a strange land.
if i’m starting on something that will be a net of 20-30 collaborating objects. it’s bad practice to write a test out at the controller. when you’re starting something big and new, the outermost layer of objects is by far the hardest to test and lease likely to be right.
can i write that test later? yes. will i? if it helps. but i’m never gonna start there.