Comment by LandR

3 years ago

Say you have to test 15 things to know it works.

Then you make a change, that change impacts 10 of those. You now need to go back and re-test, manually, those 10 thing and check they haven't broke.

That's mainly why I use unit tests, as regression testing.

Also as documentation, if I'm unsure around what a piece of code is actually doing, it's helpful to see tests that hit and find something like.

When_FooIsInThisState_ThenIExpectThisThingToHappen()

Then see the setup and expected output.

It's also good for incrementally building stuff. e.g. I have 3 scenarios I want to get working, I write a test for the first and get it passing. Then I move onto scenario 2, this requires changing the code slightly for scenario 1, but I don't have to re-test scenario 1 as I've got a unit test that is running each time I change the code that tells me it still passes, and so scenario 1 is still working. Then when I do scenario 3, I know 1 and 2 are still working without manually going back and testing them...

They can really save a lot of manual effort.

> Then you make a change, that change impacts 10 of those. You now need to go back and re-test, manually, those 10 thing and check they haven't broke.

Unit tests provide no guarantee that those 10 things haven't broke. They can break in a way that's not under test. Or they can be working individually, but breaking as a whole.

You still have to test those 10 things manually before merging.

Sure, sometimes unit tests will show you regression early on. Early feedback can be useful. But it will never give you confidence, it doesn't eliminate manual testing.

The important part is that you're making a change and you don't have confidence that it is safe. This is a signal of bad design. In most cases the right solution is to fix the design, not throw tests at the problem. There are exceptions of course, but even in those cases tests are not something to celebrate or be proud of.

It's like getting obese and then celebrating statin therapy. I mean it's great, but not as great as not being obese in the first place.

  • Agreed. That lack of guarantee generally means that it's a waste of time to even try unit testing in the first place.