When unit testing, I rarely use mocking libraries


When unit testing, I rarely use mocking libraries. Instead, I restructure the code so mocking isn't necessary.

Here's how:
1. I split the code into separate funcs. Then I test in isolation.

2. I extract code with side-effects to a separate function, and pass it in as an arg.
Here's an example of #2:

View original on X