Is Unit Testing Overused?

In this article, Andrew Hunter shares his opinion that unit tests and test driven development (TDD) now dominate the types of test that are used in software development. This situation has limited the attention available for other software testing types, such as the integration tests. Thus he asks the question: “Are unit tests overused?

Trying to write unit tests that can fail leads to write very loosely coupled and well-encapsulated components which is nice in theory. Andrew Hunter thinks that removing dependencies in this way also limit the usefulness of what can be tested and that bugs appear when the dependencies are in place. For him however, the most serious problem with unit testing is that they can destroy encapsulation. If you want to remove a dependency, you have to know what the dependency is, and expose the implementation details where that dependency is made. His conclusion is that “Tests can only detect breakage; encapsulation can actively prevent it from ever happening in the first place, so when the two concepts are at odds, it’s better to sacrifice “unit testability” for encapsulation.” He recommends to spend more time on integration and system testing. He also suggest a top-down approach of exploratory testing to verify if programs do their primary tasks.