Testing on the Toilet: Prefer Testing Public APIs Over Implementation-Detail Classes

In this blog post by Andrew Trenk, Trenk goes over what code needs to be tested, and what doesn’t, when making a Public API. Trenk goes on to explain that if a simple piece of code has only one user or is used once in another class, you should create tests for the other class or not bother testing the simple code at all. He says that anything that is an implementation detail should not get it’s own test.
In fact if you do create tests for this implementation, it might make the code and tests harder to maintain over time, it could cause issues when trying to refactor, and it could also hide issues in your code that only show when using the API. Overall Trenk suggests testing your implementation details indirectly through your API classes. This way you see that they work with your API and you have fewer tests that will need to be updated.

Advertisements