3 ms·
Because it makes refactoring very difficult. One of the original intentions of TDD and Unit testing was to make refactoring much easier. If you start testing t
by UK-AL 9y ago
Because it makes refactoring very difficult. One of the original intentions of TDD and Unit testing was to make refactoring much easier.
If you start testing the internals of function, it makes it very difficult to refactor without breaking tons and tons tests.
We only test on publicly exposed functions, and check the changes on the data or external services.
It means we can do major refactoring's of internals, keep public functions the same but tests will still pass.
One of the biggest mistakes that happened was that kent beck was misinterpreted and Unit was considered a code unit, when really it means a unit of behaviour.
- lolive 9y agoI don't disagree with your explanation. But the core point of objects is to bind a state and some method implementations. Mocking the state sounds mandatory to test the method implementations in such a paradigm. What you propose seems more like functional programming oriented testing.