What Our Tests Don’t Like About Our Code

When you start writing tests for your code, you'll likely have the feeling — bloody hell, how do I drag this thing into a test? There is code that tests clearly like and code they don't. Apart from checking the correctness of our code, tests also give us hints about how to write it. And it's a good idea to listen.

A test executes your code in the simplest possible setting, independent of the larger system it's part of. But if the simplest possible setting is how it's run in our app, and it's impossible to tease out the individual pieces — that's a bad sign. If we're saying — nah, we don't need tests. All the code is already executed in the app — that's a sign that we've created a large slab that is hard to change and maintain. As Uncle Bob put it: "Another word for testable is decoupled."

CategoriesUncategorized