Smalltalk and Object Orientation: an Introduction - Free
Smalltalk and Object Orientation: an Introduction - Free
Smalltalk and Object Orientation: an Introduction - Free
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
22.6.2 Extensibility of hierarchies<br />
Another problem associated with polymorphism is presented when <strong>an</strong> operation, which possesses one or<br />
more parameters which are polymorphic, is being tested. That is, the operation c<strong>an</strong> be called with a<br />
r<strong>an</strong>ge of different types of object as a parameter. For example, a parameter may be assumed to be a<br />
collection, however it could be a set, a bag, <strong>an</strong> array, a list, a sorted collection or <strong>an</strong> ordered collection.<br />
Each of these have specific features which may or may not affect the operation of the method. They<br />
may also contain elements which are of <strong>an</strong>y type, which in turn may or may not affect the method’s<br />
behavior.<br />
As testing a method consists of checking its effects when executed for various combinations of<br />
actual parameters, a test suite must ensure that all possible input types are covered. This of course<br />
implies that some form of specification exists which specifies the acceptable r<strong>an</strong>ge of input types.<br />
However, it is impossible to pl<strong>an</strong> a set of tests in which you check all possible parameter values for a<br />
method. This is because the r<strong>an</strong>ge of different types of o bjects which could be presented to a method is<br />
huge in <strong>Smalltalk</strong>. Remember that the hierarchy of classes is very large (e.g. every class under<br />
<strong>Object</strong>) <strong><strong>an</strong>d</strong> is freely extensible. For example, I c<strong>an</strong> define my own stack <strong><strong>an</strong>d</strong> queue collection<br />
classes. However, even if the method I am testing includes a test to see if it has been presented with <strong>an</strong><br />
inst<strong>an</strong>ce of a collection class, it could easily encounter a type of collection class for which it was never<br />
designed. Remember you (or <strong>an</strong>yone else) c<strong>an</strong> extend the set of collection classes whenever you wish. If<br />
the method is part of a class which is to be provided as part of a set of “highly” reusable classes, either<br />
within a single project or for external use, this is a signific<strong>an</strong>t issue.<br />
22.6.3 Heterogeneous containers<br />
As has been briefly mentioned above, there are m<strong>an</strong>y classes which are designed to hold elements<br />
which may be <strong>an</strong>y inst<strong>an</strong>ce in the system. In <strong>Smalltalk</strong>, this me<strong>an</strong>s that they c<strong>an</strong> hold inst<strong>an</strong>ces of<br />
classes, classes, metaclasses etc. If the tester is considering a met hod which will be applied to, or will<br />
consume, the members of such a heterogeneous container (e.g. a collection), it is almost impossible to<br />
ensure that a complete r<strong>an</strong>ge of tests has been performed. For example, it may be assumed that all the<br />
members of su ch a container are conventional inst<strong>an</strong>ces of user defined classes, however there is<br />
nothing to stop the member of one of these containers being a class or the system dictionary etc.<br />
In such situations care must be taken to ensure that reasonable usage of the method has been tested.<br />
In other words, with reference to the classes specification, assumptions must again be made, this time<br />
about the use of the method. Again, these assumptions should be documented so that they c<strong>an</strong> be<br />
challenged if necessary at a later date.<br />
22.7 Additional <strong>Smalltalk</strong> specific features<br />
22.7.1 Block evaluations<br />
Blocks introduce <strong>an</strong>other complexity to the testing process which is particular to <strong>Smalltalk</strong>. Not only are<br />
they more difficult to test physically (it is more difficult to get hold of them i n isolation), they also<br />
execute in the context within which they were created (rather th<strong>an</strong> the context in which they are<br />
evaluated). This second issue is import<strong>an</strong>t because in m<strong>an</strong>y situations a block is defined in one place,<br />
<strong><strong>an</strong>d</strong> then passed as a parameter t o <strong>an</strong>other place, where it is evaluated. If the receiving method is being<br />
tested, it is impossible to conceive of all the contexts in which the block could be created <strong><strong>an</strong>d</strong> therefore<br />
impossible to produce a comprehensive test suite. Again, care must be taken to test the receiving<br />
method against its specification <strong><strong>an</strong>d</strong> not the assumptions which this led to.<br />
In addition when they are examined in the debugger, they are treated in a different way to general<br />
<strong>Smalltalk</strong> code, which makes it more difficult to follow the thread of execution. Instead of immediately<br />
stepping through the code in the block, it is necessary to step down into the value method <strong><strong>an</strong>d</strong> then into<br />
the block. It is all to easy to step over the block <strong><strong>an</strong>d</strong> fail to see the result.<br />
188