|
|
|
|
|
by tsimionescu
950 days ago
|
|
It is very common for unit tests to be white-box testing, and thus to depend significantly on internal details of a class. Say, when unit testing a list class, a test might call the add function and then assert that the length field has changed appropriately. Then, if you change the list to calculate length on demand instead of keeping a length field, your test will now fail even thought the behavior has not actually changed. This is a somewhat silly example, but it is very common for unit tests to depend on implementation details. And note that this is not about private VS public methods/fields. The line between implementation details and public API is fuzzy and depends on the larger use of the unit within the system. |
|
Checking length is now a function call and not a cached variable — a change in call signature and runtime performance.
Consumers of your list class are going to have to update their code (eg, that checks the list length) and your test successfully notified you of that breaking API change.