Write testable code
Bad code leads to bad unit tests.
Bad unit tests lead to bad code.
There are many aspects to good code, but two important practices that enable unit testing are :-
- Always inject dependencies
- Avoid global state (singletons, static variables, ThreadLocals, registries etc)