Discussion about this post

User's avatar
Alastair Danley-Cox's avatar

Reminds me of debates I've had about what is a unit test / integration test / end-to-end, yada yada test. I try to call them microtests these days (stealing a term I heard from Gee-Paw Hill) to avoid that conversation as at the end of the day I think it's probably all subjective, and doesn't lend itself to what matters more.

So when you've mentioned tests that test a wider range of functionality (I think of this as black-box testing, where I don't care how it is actually working inside), it struck a chord with me. This again appears to be about the "width" of the test (this is often the sticking point in discussions around what is a unit test etc.) - I've worked places with a purist test approach where we were actually testing the getters and setters of a class, for example.

I look back and think, sure they were valuable, but at that level of granularity, whether or not the correct definition of a unit test, at some level they become cumbersome, and I'd rather "widen" the microtest and test the class as a black box, unless there are some particularly interesting methods associated with it. And the chances of that depend on what sort of job the class is supposed to do (say, DTO vs. domain behaviour)

I could then decide, you know what, I've widened this test for pragmatic reasons, and because I don't see as much downside as I do in their maintenance. it's all good, it adds value, and is exactly what I need right now.

I don't really see why widening those tests even further, say from a single class treated as a black-box, to a family of classes all treated as a black-box, is a problem - that is to say, I would not write the smaller tests that tested the innards, just the wider ones that test composites of classes etc. And if at some point, I see a need to change that, to write a smaller test, then have at it.

Thanks for your insights :)

Expand full comment

No posts