Art of Unit Testing: Part 2
wtanksle at dolphin.openprojects.net
Fri Aug 24 22:02:17 CEST 2001
On Fri, 24 Aug 2001 11:51:07 -0700, Jesse F. W wrote:
> I have another Testing related question. How are unit tests done
>when the units to be tested get lots of information from nested
>objects, e.g. (in a method of a class to be tested):
>how would this be tested?
It wouldn't -- it would be deleted and abhorred. That's a violation of
encapsulation and of the law of Demeter (google that if you don't know
what it means).
The problem is that each object should have an interface to do everything
it needs to do. You shouldn't have to reach inside any object to inspect
how it's doing its job. The above code should look like 'if
self.app.anyPlayersInStoppedBattles():' (I'm assuming that's an
However, your question still remains: how do you unit test objects which
are supposed to delegate operations to other objects? The answer is that
you write the unit test without assuming any delegation. That method you
mentioned should work whether or not delegation is happening; and your
test won't care, because it only tests the method, not the implementation.
-William "Billy" Tanksley
More information about the Python-list