Hacker News new | ask | show | jobs
by sagacity 515 days ago
I agree with the sentiment of the article: I've seen too many codebases where a lot of stuff is being tested via unit tests (sometimes even via heavy mocks). The main implication is that your code essentially becomes impossible to refactor, since you're basically testing how your internals are wired up and any change to your code structure immediately causes a big chunk of tests to fail even though on the outside everything still works.

Having said that, I think this mostly means that people find the term "unit" in "unit tests" ambiguous and they're just cargo culting it to mean "a single class" or whatever. That's the fundamental flaw that should be addressed. Basically that's what the article is saying as well, I guess, by implying that the API is the contract you should be testing, etc. But that is essentially just a long winded way of saying "The API is the unit".