3 ms·
Unit tests are a fantastic tool, but they have clear limitations. Tests (unit, integration, system, acceptance or any other kind) should do two things: - whil
by jaimebuelta 10y ago
Unit tests are a fantastic tool, but they have clear limitations.
Tests (unit, integration, system, acceptance or any other kind) should do two things:
- while developing, help checking that the code is doing what it should (e.g. fixing the bug)
- after developed, ensuring that the code keeps doing it.
(ideally also ensure that it doesn't do anything not supposed to do, but that's much more difficult)
That's why the best tests should aim for weak spots and try to give a good assurance that, if there are defects, the test should have a good chance of failure....
Those weak spots sometimes will be in single functions, but other times they won't.
Creating tests just for the sake of having them, not adding a better chance of them failing when a problem arises is just wasted time. Or worse, coupling the tests with implementation details that are irrelevant (for example, this function is divided in two or three because is big, just to add readability) is just pointless....