Private properties are private, unit tests should not access them. Otherwise, you have tight coupling between your classes and the tests, and you can't do refactoring, or really change anything without doing at least double the amount of work, probably more. Mocks are not for accessing private fields, they are for simulating an aspect of a behavior of a public dependency. Tests are best thought of as a stand in for the calling code (clients); if a client can't directly access it, the tests shouldn't as well. The goal is to test the externally visible behaviors of the component under test.
↧