Search⌘ K
AI Features

Test Maintenance Cost

Explore the impact of interface changes on unit tests and the costs associated with maintaining them. Understand design problems such as code duplication, violation of single responsibility principle, and testing private methods. Learn how refactoring and improving design can ease test maintenance and enhance test clarity and coverage.

The change to the interface with Profile broke a number of tests in ProfileTest. We need to invest some effort to fix the tests, which highlights one of the costs of using unit tests in the first place; they need to be maintained regularly.

Refactoring

Refactoring is supposed to be an activity where we change the implementation of the code without changing its behavior.

Our tests are supposed to be a reflection of the program’s behavior. However, the reality is that we are changing the behavior of our classes in terms of how we expose that behavior through the classes’ interfaces.

We accept the cost of fixing broken tests because their value can be far greater than the effort we put into them.

There is certainly some benefit of being able to make changes without the worry of breaking other codes, especially ...