They are cheap per unit, but if you test a lot of units, it adds up.
There is a set of bugs that only higher-level testing will catch. There is another set of bugs that both higher and unit-level testing will catch. Then there is the set that only unit-level testing will catch.
How important is that last set? If a unit test fails and there is no user interaction to trigger that failure, is it really a bug?
Unit tests can be valuable if they help you during development of a unit, but most units are not that complex and should not require unit tests.
Cost includes the impact on further tests and maintenance.
The cost of testing and debugging increases as you go down the development/release cycle.
If you have unit tests then that helps integration tests (less issues, easier to investigate), system tests, etc. all the way down to dealing with bug reports from the field.
> but most units are not that complex and should not require unit tests.
> If you have unit tests then that helps integration tests (less issues, easier to investigate), system tests, etc. all the way down to dealing with bug reports from the field.
Not in my experience. I don't see how a unit tests helps me with bugs that show up in the field. If it shows up in the field, something should've caught it, which means testing failed.
There is a set of bugs that only higher-level testing will catch. There is another set of bugs that both higher and unit-level testing will catch. Then there is the set that only unit-level testing will catch.
How important is that last set? If a unit test fails and there is no user interaction to trigger that failure, is it really a bug?
Unit tests can be valuable if they help you during development of a unit, but most units are not that complex and should not require unit tests.