Member-only story
Simple Code Is Testable Code
Testing doesn’t have to be difficult

Writing code is a skill like any other. You need practice and practice. You need to read good code to see what it looks like. You need to try some things to see how they turn out to understand what works and what doesn’t.
Sometimes, the code you write doesn’t quite feel right. You did your best, but you still think you could have written it better. Any self-respecting coder feels that way at some point. And it’s OK: you won’t always write the best code every time.
But one thing you cannot ignore is testing your code.
Groans all around, right? The second any software engineer mentions testing, suppressed memories of either flakey tests, useless unit tests, or tests that don’t test anything begin to arise.
Testing shouldn’t be that way. And it starts with simple code.
Testing Shouldn’t Be Hard
One of the common problems with testing, at least white-box testing, is that the code is too complicated. There aren’t clear class hierarchies. Everything affects everything.
The state is shared across multiple objects, keeping you from asserting changes in a single place. The setup for one test alone is 20 times more lines of code than the actual test.