Yesterday, I ran across a unit test at my work that had fourteen lines of “arrangement”, one line of “action”, and ten lines of “assertions.” The unit test literally had more lines than the method it tested!
The author of that unit test should have figured out at that point that they had ended up with some bad implementation. To that end, I have a small list of indicators brought to light by unit tests that I use to help me understand if I have a poor implementation.
I identified these indicators because I have written code sometime in my past that I would now find offensive because of the bad design it implied. Unit tests that have any of these flavors can imply something wrong with your implementation.
This one, the “too deep of an arrangement” indicator allows us to realize that we’ve inadvertantly broken the Law of Demeter.
If, in your test, you have a mock that returns a mock that returns a mock (or stubs), then your class knows too much about its collaborrators. Your class has asked questions of its collaborators rather than telling them to do something.
To fix this problem, you should have the class under test tell its collaborator what to do rather than ask for an intermediate result.