News for hackers. Stuff that matters.
Re:A Theory of Software Architecture by MeteorMarc on Wednesday October 28, 2020 @05:39AM (#24916909)
You only want to test on public API, because else you cannot change the implementation without adapting your perfect unit test on implementation details. So, I prefer the first code example and do not mind some mocking (unless the extracted functions make sense on the public API).
Re:A Theory of Software Architecture by valenterry on Wednesday October 28, 2020 @11:54AM (#24920262)
If you take that idea/ideal to the very logical end, then you can only do system tests / acceptance tests (however you want to call it). Your tests must only be able to do what end-users do - everything else would be relying on implementation details. No unit tests at all!

...unless we take a more compositional approach and define our application to consist of many "parts" each of which has a public API and an implementation. Well, in that case I would argue that each function can be considered as such a part, having a public API (the definition of its inputs and outputs) and an implementation that can be changed while keeping the public API stable.

Over the time I came reached a conclusion: whenever I have to run some code to be sure it does what it should, I write a test instead. And every often that is a unit test. If I'm highly confident that the code will do what I expect, then I rely on very high level system tests, unless I fear that someone might break the code later by accident without the compiler (or other existing tests) being able to detect that.

Re:A Theory of Software Architecture by winkeltripel on Wednesday October 28, 2020 @06:26AM (#24917172)
A large application has lots of implementation leak to the API, doesn't it?
Re:A Theory of Software Architecture by Izkata on Wednesday October 28, 2020 @09:23AM (#24918427)
For this reason, when mocks are involved (that is, just about any external API), I think Listing 2 is the ideal - extract a small function designed around the desired interface, a facade that's easily mockable and won't change with the library implementation.