[DUG] Unit Testing
Allan, Samuel
S.A.Allan at massey.ac.nz
Wed Jun 15 18:21:38 NZST 2005
Re: Shower Testing
You are advocating an approach similar to the one I have taken. I am
assessing a student's academic record against the regulations governing
their programme of study.
The most complex type of rule is a composite of three different
strategies and another composite object. Each of these component classes
has a set of unit tests. At the bottom level, these classes are very
simple and consequently so are their tests.
When I am testing the rule class I construct it using mock component
classes, which behave how I tell them to, and took all of ten minutes to
write. The tests for the rule class simply check that the logic in the
rule class is correctly looking at it's components, which I can tell,
because the mock components are doing as I say.
Sometimes the rule's logic is sufficiently complicated to make this
impractical via it's public interface. I have created test descendent
rule classes that redeclare the protected methods which make up the
logic as public. I then test them, then check that the public methods
are calling them correctly.
This seems to have worked well for me, and I have yet to find out I have
caused myself problems with this approach.
Samuel Allan
More information about the Delphi
mailing list