DEV Community

Discussion on: Unit tests dos and don'ts

Collapse
 
dakujem profile image
Andrej Rypo

Yes, that's correct. I found myself however, that testing private and protected methods does make sense in certain cases.
Imagine a complex public method that abstracts part of its logic into private methods. Testing these, if there is an error, you will probably identify it easier if the error also shows in the tiny private method.
Furthermore, if you are building your class/app logic from bottom up using TDD (test driven dev), you will most probably encounter cases where you write tests for methods that you design as private.
Otherwise, I fully agree that if something is not used, it should be refactored.