One of the testing mantras is that a good test is cheap to write but can capture important bugs. Unit tests are cheap to write, so we do not have to think much about cost.
Larger tests may not be cheap to write, run, or maintain. I have seen integration test suites that take hours to run—and cases where developers spend hours writing a single integration test.
Therefore, it is fundamental to perform a simple cost/benefit analysis. Questions like “How much will it cost me to write this test?” “How much will it cost to run?” “What is the benefit of this test? What bugs will it catch?” and “Is this functionality already covered by unit tests? If so, do I need to cover it via integration tests, too?” may help you understand whether this is a fundamental test.
The answer will be “yes” in many cases. The benefits outweigh the costs, so you should write the test. If the cost is too high, consider simplifying your test. Can you stub parts of the test without losing too much? Can you write a more focused test that exercises a smaller part of the system? As always, there is no single good answer or golden rule to follow.
Leave a Reply