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.3.2 Incremental testing<br />
Incremental testing is one obvious <strong>an</strong>swer, i.e. we don’t w<strong>an</strong>t to re -test the whole class if we don’t need<br />
to, only those elements which have been affected by the additions in the subclass need to be tes ted. Of<br />
course this is the key issue here: what determines whether or not we “need to” re -test a subclass. One<br />
<strong>an</strong>swer is that it is the properties of the class which are affected by the subclass, including which<br />
inst<strong>an</strong>ce variables may be altered <strong><strong>an</strong>d</strong> which methods may be directly or indirectly affected, which<br />
determine what should be re-tested. For example, a directly affected method may be one which is called<br />
by a (re)defined method in the subclass or which directly references <strong>an</strong> inst<strong>an</strong>ce variable which is<br />
modified by (re)defined methods. Indirectly affected methods are much harder to identify. They are<br />
methods which may be affected due to a chain of interactions. For example, suppose that a method “ a”<br />
references <strong>an</strong> altered inst<strong>an</strong>ce variable <strong><strong>an</strong>d</strong> modifies <strong>an</strong>o ther inst<strong>an</strong>ce variable. This results in a second<br />
method operating in a different way generating a different result which is used by a third method. The<br />
third method is indirectly affected by the original ch<strong>an</strong>ge in the inst<strong>an</strong>ce variable. In the worst case,<br />
every element of a class may be affected in such a way. In such cases, either the whole class must be retested<br />
or the developers must use their own intuition <strong><strong>an</strong>d</strong> experience to decide how much testing is<br />
required.<br />
A subtlety which c<strong>an</strong> often be missed is t hat although <strong>an</strong> inherited method has not been ch<strong>an</strong>ged, a<br />
method which it calls may have been redefined in the subclass. Thus the inherited method is directly<br />
affected by the subclass <strong><strong>an</strong>d</strong> must be re-tested.<br />
However, we w<strong>an</strong>t to be sure that <strong>an</strong>y inherited fu nctionality has not been adversely affected in <strong>an</strong><br />
un<strong>an</strong>ticipated way (note that this implies that we have some sort of specification against which we c<strong>an</strong><br />
compare the functionality of the class). We must therefore also consider some form of regression<br />
testing. This c<strong>an</strong> be achieved by defining <strong>an</strong> appropriate set of regression tests on the class side of the<br />
root superclass. These tests c<strong>an</strong> then be performed whenever the root class or one of its subclasses is<br />
ch<strong>an</strong>ged in <strong>an</strong>yway. Ideally these tests should include their own evaluation so that a report c<strong>an</strong> be<br />
generated (to the Tr<strong>an</strong>script or to a file) stating the result of the tests. If appropriate, additional tests c<strong>an</strong><br />
be defined (in subclasses of the root superclass) to test the added functionality. If new tests a re defined<br />
each time the functionality is extended or modified, then the tests on the class side also act as a<br />
repository of testing knowledge which c<strong>an</strong> be exploited by future users of the classes without the need<br />
to underst<strong><strong>an</strong>d</strong> their full functionality.<br />
22.4 Abstract superclasses<br />
Abstract superclasses bring together common features, which are to be used in m<strong>an</strong>y subclasses.<br />
However, from a testing point of view they are a difficult problem. The definition of <strong>an</strong> abstract<br />
superclass is a class which is never intend ed to be inst<strong>an</strong>tiated <strong><strong>an</strong>d</strong> which does not provide, in its own<br />
right, enough functionality to be useful. Given these two features, it is extremely import<strong>an</strong>t to test<br />
abstract superclasses thoroughly. However as they do not provide enough information to create <strong>an</strong><br />
inst<strong>an</strong>ce of the class, it is impossible to test the class directly. The tester should provide a subclass<br />
which acts as a test harness for the facilities defined in the abstract class (such a class c<strong>an</strong> be easily<br />
removed from the <strong>Smalltalk</strong> image).<br />
The test subclass might provide a wide r<strong>an</strong>ge of facilities. For example, a method may be defined<br />
which sets the state of the inst<strong>an</strong>ce such that a particular method c<strong>an</strong> be called <strong><strong>an</strong>d</strong> then sends a message<br />
causing the method (inherited from the parent class) to be executed.<br />
Note that testing the abstract superclass does not me<strong>an</strong> that exhaustive testing of the methods in the<br />
subclasses, which inherit from it, is not required. As each subclass has ch<strong>an</strong>ged the context within<br />
which the method will be run, the same appr oach to testing as discussed in Section 3 must be<br />
performed.<br />
22.5 Encapsulation<br />
Encapsulation is a great bonus from the point of view of the user of <strong>an</strong> object - they do not need to know<br />
<strong>an</strong>ything about the object’s implementation, o nly what its published protocols are. This also me<strong>an</strong>s that<br />
the developer of the class knows that <strong>an</strong>y potential users will have to come through the front door etc.<br />
185