Vlad's Roam Garden

Powered by 🌱Roam Garden

treat challenges with writing unit tests as a feedback about your design

When you write unit tests - you can find that the code your'e testing is hard to initialize/use/integrate with

This should serve as a feedback for your design - you should refactor your code to make it easy to test, reducing it's coupling to other components, making it's dependencies explicit, etc

(as opposed to using clever tools to hack into/set up your components)

There are several frameworks available that use techniques such as manipulating class loaders or bytecodes to allow unit tests to break dependencies without changing the target code. As a rule, these are advanced techniques that most developers would not use when writing production code. Sometimes these tools really are necessary, but developers should be aware that they come with a hidden cost.
Unit-testing tools that let the programmer sidestep poor dependency management in the design waste a valuable source of feedback. When the developers eventually do need to address these design weaknesses to add some urgent feature, they will find it harder to do. The poor structure will have influenced other parts of the system that rely on it, and any understanding of the original intent will have evaporated. As with dirty pots and pans, it’s easier to get the grease off before it’s been baked in.