DEV Community 👩‍💻👨‍💻

Discussion on: Do you unit test private methods?

aetelani profile image
Anssi Eteläniemi • Edited on

I don't think there is right answer. While coding a class, It is good thing to have 'glass box' access to everything and make a test case out of it rather than opening debugger or printing states.
After the code is developed, Ii is useful to save these tests as mementos. If there comes bugs later, private member tests help fixing the code and conform to the assumptions how code should work. This also helps avoiding regression.
Testing implementation internals is not necessary to do on every build, and can take lot of time. So it is preferable to make different test sets to different purposes and run when it fits the purpose.