Smalltalk and Object Orientation: an Introduction - Free
Smalltalk and Object Orientation: an Introduction - Free
Smalltalk and Object Orientation: an Introduction - Free
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
23.1.6 Tracing a classes operation<br />
In order to trace a classes operation it would be possible to create a subclass which mirrored the parent<br />
classes methods exactly. The subclasses methods could print the value of <strong>an</strong>y parameters into the<br />
method before calling the method <strong><strong>an</strong>d</strong> then <strong>an</strong>y results returned by the method. If necessary tests could<br />
be performed to ensure that the parameters or the returned value were within <strong>an</strong>t icipated r<strong>an</strong>ges. The<br />
adv<strong>an</strong>tage of testing the class method calls in this way would be to encapsulate all the test information<br />
into a test subclass which could be removed from the <strong>Smalltalk</strong> image for the delivered system.<br />
23.1.7 Sources of test information<br />
The con cept of use cases discussed earlier in this book is <strong>an</strong> import<strong>an</strong>t source of test cases.<br />
Opportunities for the merging of the use case specifications into test specifications abound.<br />
A style issue, rather th<strong>an</strong> a testing issue, is that it is good style to pro vide a set of test examples,<br />
often on the class side, which exercise some behavior of the objects of the class. These c<strong>an</strong> be used to<br />
illustrate how to use the objects of the class. They c<strong>an</strong> also act as a form of regression testing either<br />
when the class is modified or when a subclass is defined. If these test methods are placed in appropriate<br />
protocols, then the whole protocol c<strong>an</strong> be filed out in one go, thus creating a test file.<br />
23.2 <strong>Object</strong> integration testing<br />
The above section deliberately only deals with the issue of testing a class in isolation. This involves<br />
individual method testing followed by testing combinations of methods. <strong>Object</strong> integration testing<br />
involves testing inst<strong>an</strong>ces of the same or different classes when they are collaborating in some<br />
operation. This is different from traditional procedural integration testing as the structure of traditional<br />
programming l<strong>an</strong>guages is fairly rigid <strong><strong>an</strong>d</strong> is unlikely to vary while the system is executing. It is also<br />
different from statically bound procedural programs, because when a l<strong>an</strong>guage such as Pascal is used,<br />
the compiler is able to test to see whether the called procedure or function definition matches the calling<br />
definition. For example, if a procedure expects <strong>an</strong> integer as a parameter the compiler checks that <strong>an</strong><br />
integer is being presented to it.<br />
In <strong>Smalltalk</strong>, neither the structure of the objects is fixed nor are the actual types of parameters etc.<br />
likely to be known. It is therefore necessary to perform object integration testing in a methodological<br />
<strong><strong>an</strong>d</strong> principled m<strong>an</strong>ner. If the specification of two classes indicates that they are intended to collaborate<br />
to achieve some behavior, then those two classes should be tested together. Again the specification<br />
should be used to generate scenarios which exercise normal <strong><strong>an</strong>d</strong> abnormal interactions. These scenarios<br />
c<strong>an</strong> then be used to define tests to perform. Having tested the two classes other cooperations may be<br />
identified involving these <strong><strong>an</strong>d</strong> other classes. Each of these collaborations also needs to be tested.<br />
Integration testing (like multiple method testing in a single class) relies on the identification of<br />
scenarios which will be used to define appropriate test suites. However, consideration should also be<br />
given to identifying <strong>an</strong>ticipated message paths. The differences b etween these two tests are akin to<br />
black box <strong><strong>an</strong>d</strong> white box testing for a single method. The scenario based testing relies on testing the<br />
specification of the behavior of the collaborating objects, while the white box testing is intended to test<br />
particular message paths through the classes. Again, the two approaches to testing are intended to be<br />
used together.<br />
23.3 System testing<br />
System testing of <strong>Smalltalk</strong> systems should be carried out in essentially the same way as system testing<br />
of <strong>an</strong>y computer system. This is because a system implemented in <strong>Smalltalk</strong> should be subject to the<br />
same types of requirements as a system written in <strong>an</strong>y other l<strong>an</strong>guage. There are some special situations<br />
which you might wish to test for, such as ensuring that the system does not run out of memory before a<br />
garbage collection is forced or that the system will still work once the image has been “stripped” of<br />
those classes not required by the production system (e.g. the compiler classes etc.). However, in general<br />
the system should be subject to the same r<strong>an</strong>ge of tests as <strong>an</strong>y other.<br />
192