Hard-to-test code is a design smell. Writing unit tests exerts pressure that improves software in two ways. First, modularity: if a class is hard to test, itβs doing too much: too many input combinations, too many side effects, too many conflated concerns. The cure is extraction. Second, dependency injection: code that constructs its own dependencies internally is untestable without expensive integration infrastructure, so tests force you to inject from outside, making dependencies explicit and swappable.
This is testability as a design heuristic, not just a verification mechanism. The tests arenβt checking behavior. Theyβre revealing structural problems.