Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Alternatively, if an internal function is important enough to need good coverage, it should be pulled out into an internal "library" that exposes the interface explicitly (even if this is just a separate file or folder with limited visibility to the rest of the codebase).

Testing internals is almost always a code organization smell IMO.



If you seek good coverage, you undoubtedly would be better off moving that against the public interface.

"private" tests are more for like when you're having trouble figuring out an edge case failure and want to narrow it down to a specific helper function to aid debugging or if you need help coming up with the right design for an internal function. As before, we're talking exceptional circumstances. Rarely would you need such a thing. But if it helps, no need to fear it.

Either way, I'm not sure you would be looking for good coverage, only the bare necessities to reach the goal. Once settled, the tests are disposable. Organizing your project into internal libraries in case you encounter a debugging problem in need of assistance, for example, is extreme overkill.


Hmm, I guess I don't really consider throwaway assertions in pursuit of debugging "tests" in the typical sense.

I certainly wouldn't advocate for code reorganization for that case, but if there is a property that is important to maintain over time that isn't easily expressed by exercising the public API, it does suggest that reorganization is probably in order.


> Hmm, I guess I don't really consider throwaway assertions in pursuit of debugging "tests" in the typical sense.

I agree it is not "tests" in the documentation sense, and I did mention that, but, regardless, you do seem to align on "throwaway". Now you have me curious, what kind of ephemeral "tests" were you imagining if not something similar to what I described in more detail later?


I suppose I was imagining tests that are created to validate an internal piece of code when it's first built or refactored, not necessarily in pursuit of a specific observed bug.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: