Need feedback on simple idea
andreas.raab at gmx.de
Sat Apr 12 02:28:39 UTC 2003
> Sometimes it happens to me that when writing Unit Tests I
> want to check internal state of an object, for example to see
> if it was affected by a message, and I end up writing (previously
> not needed) accessors for some of the instance variables.
> Am I the only one?
Certainly not. But the argument can be made that this is really a bug of the
testing environment (I presume you're using SUnit like everyone else) as it
forces you to break encapsulation here. In fact, I'd claim that writing
tests "outside" of the context of the class you are working on is one of the
primary reasons why people often _don't_ write tests. To me, the tests
really should be embedded right into the method you're writing - making
extra classes, accessors and the like just gets into your way and detaches
the place where you find the code from the place where you find the test. It
can be tremendously hard to guess in which class exactly you may find a test
(if any) for a certain method.
More information about the Squeak-dev