SUnits documentation Re: Is this list a chat or a list REALLY ?

Markus G ä lli gaelli at emergent.de
Sun Aug 19 20:59:42 UTC 2001


Göran  Hultgren wrote:

> BTW - I have sortof realized that you can gradually build TestCases using
> inheritance. For
> example, first I build a testcase with an empty model being instantiated in
> the setUp method. This
> typically exercises "building" the model from scratch etc.
> 
> Then I inherit and let the new setUp be typically:
> 
> super setUp.
> model add: 'hubba'; add: 'bubba'.
> 
> ...and then I test a filled model with those testmethods.
> 
> Is this a pattern other people use too?
> 
Hi,

as I think the most difficult part in writing tests is setting up the
fixtures (or example-objects), the situation you describe sounds very known
to me. You just want to reuse your complex examples in other
test-situations. 
I'd call this situation "example composition".
What you do by inheriting test-cases, could also be done by extending the
"classes in test" on the class-side with example-methods. This
example-methods could reuse other already existing examples.

Coming back to your example, which just composes one example out of a basic
example, I would program the following (always in an "examples" category).

Foo class >> exampleBasic
    ^self new
        foo1: someTestdata1;
        foo2: someTestdata2;
        yourself

Foo class >> exampleHubbaBubba
    "self exampleHubbaBubba"

    ^self exampleBasic
        foo3: 'hubba';
        foo4: 'bubba';
        yourself

Then we don't even need the setUp-Method as we can write
FooTest >> testFoo5
    "self testFoo5"

    |someDesiredResult|
    someDesiredResult := (...).
    self assert: (Foo exampleHubbaBubba foo5 = someDesiredResult)

This also has the advantage that we could test different examples and don't
have to setUp all of them every time we just want to use one. (SUint creates
an instance of FooTest for every test-method and initializes it in setUp)

If we really need to separate the tests and examples from our "real program"
it is certainly nice to have some kind of envy-like extension mechanism,
which we might get with modules in the near future.


Markus





More information about the Squeak-dev mailing list