What’s the “unit” in unit testing and why is it not a class

Why care about the scope of testing?

Somewhere in 2018, I asked my Twitter friends for advice on defining a heuristic to define the right scope of your unit tests. This resulted in some interesting discussions, but I still remember two responses that somehow stuck. I particularly liked the humor in the first one:

When someone else can modify your code safely, without you getting sweaty armpits, the scope of your unit test is okay

The other one sounded more thoughtful and wise:

Our unit test should be large enough that you can assert something meaningful, but small enough that you can quickly read & assess it

You may wonder why we should care about this in the first place. Well, I hope you do agree with the value of unit testing. In my experience, It can help produce code that can be changed by any developer in the team without fear and with confidence. But unit tests do not come for free. They can easily extend the initial development time with 50%. But I promise you, your return of investment will be significant. You’ll end up with happier developers and happier clients.

But that’s not what I meant with “free”. The “dark side” of unit testing and Test Driven Development, as some like to call…

--

--

Dennis "The Continuous Improver" Doomen
Dennis "The Continuous Improver" Doomen

Written by Dennis "The Continuous Improver" Doomen

Dennis is a veteran architect in the .NET space with a special interest in writing clean code, Domain Driven Design, Event Sourcing and everything agile.

Responses (1)