#development #reading-list #testing

🔗 If you mock, are you even testing?
understandlegacycode.com

Have you ever felt like you're making the code harder to read for the sake of testing?

Imagine, you have this existing code and it's not tested. It does a bunch of side-effects. People say you should put that code under tests before touching it.

So you begin to follow advice like passing globals as parameters or extracting problematic side-effects to mock them in tests.

But the more you go, the more it feels off. You end up with a lot of mocked states and data so you can write your fast and reliable unit tests. In the end, it looks like you've created an entirely different class that doesn't accurately represent the actual code.

You pause and think:

"Is it fine to change code signatures for the sake of testing?"

"Am I testing the actual code or an entirely different class where real things won't happen?"

This might create a dilemma for you. Are you sure it's worth continuing with this approach or is it a waste of time?

The million-dollar question is: should you rather write unit or integration tests on Legacy Code?

continue reading on understandlegacycode.com

⚠️ This post links to an external website. ⚠️