[squeak-dev] Re: Subclassing tests Style Question

Markus Gälli gaelli at emergent.de
Mon Jul 21 18:08:47 UTC 2008


Hi Herbert and Zulq

>
> Sounds to me like you should delegate set up to a helper class that  
> is used by both test case classes. Perhaps even a TestResource  
> (http://www.metaprog.ch/downloads/TestResources.pdf).

I'd create a bunch of example methods on the class side of A (e.g. A  
class >> example1 and A class >> example2 ...) and a method which  
would return all of them:
A class >> examples
	^{self example1. self example2 ... }

then you just call them in your test BTest -- or continue to write  
this example style, throw an assertion at the end here and there or  
even some post conditions or invariants.

To make this "monkey patching" as some might call this a bit more  
maintainable, ensure to put those extensions in some test package by  
prefixing the method category with sth. along the lines of  
"*MyPackage-Tests" to tell monticello not to include them in the  
"real code"-package but in some test package.

Then, of course ;-) , patch SUnit to collect those example methods  
and run them, after ordering them so that only the high level  
examples need to be called/tested.
I never came around doing so, though it is not that hard -- others  
did for Java:

http://www.iam.unibe.ch/~akuhn/blog/2008/04/jexample-quickstart/

Thanks Adrian!

Cheers

Markus

>
> Regards,
> Zulq.
>
> Herbert König wrote:
>> Hi,
>> I have two classes say A and B.
>> B has a collection of A which is quite complex.
>> Laziness suggests to make BTests a subclass of ATests so I could  
>> reuse
>> the (lengthy) setUp of A in A tests. Something like
>> BTests>>setUp
>>  super setUp
>>  ..stick a copy ATests A into BTests B
>>  super setUp
>>  ...add a slightly modified copy of ATests A into BTests B
>> The gut feeling says BTests should not inherit from ATests if
>> B does not inherit from A.
>> But copying all that A setup code from ATests to BTests does not seem
>> right either.
>> Hey that's the first time I think using a Trait might not be that
>> bad??
>> Making a class with the only purpose to return initialised instances
>> of A??
>> Any advice is much appreciated!
>> Thanks,
>> Herbert
>
>




More information about the Squeak-dev mailing list