You are on the right track. You do not want fragile tests to be changed every time you reorganize the system under test.
In general, I focus my testing on the public interface. If your public interface changes, you may have to change more than just tests.
I also try to do state testing instead of checking behavior when possible. Therefore, I usually use stubs instead of mocks . (Most isolation / mocking frameworks will allow you to create one.) I check the state of the system (or class) under test, and do not request that the mock object check itself.
However, I try to be flexible. If testing fraudulent behavior makes sense in this case, I will use it. If I need to expose the insides to get decent coverage, I will.
EDIT . See also the article by Scott Ben .
source share