3 ms·
Also, non-public fields make unit testing a pain. I like to put my unit tests in separate classes, in a separate source root directory (for the convenience of
by csense 14y ago
Also, non-public fields make unit testing a pain. I like to put my unit tests in separate classes, in a separate source root directory (for the convenience of my build script), and ship them in a separate jar. But if I want to test private methods or have the tests check the values of private variables, it simply can't be done without violating the separation of test and non-test code by putting test code in the class being tested.
- bunderbunder 14y agoAt least in my language of choice (C#), the general wisdom is that feeling a need to unit test against an object's internal state is a code smell. It suggests that your class is violating the single responsibility principle and needs to be separated into multiple smaller ones. Writing tests against implementation details makes the code less maintainable, since it means that you won't be able to change those implementation details without rewriting (or worse yet, just commenting out) unit tests.