I wonder what the advantages of using Traits over creating a test
class hierarchy mirroring the collection hierarchy is?

When you change a test you have to go to all your hierarchy.
Traits do that for you for free.

Normally the tests in TEmptyTests should be valid on all collections
and should thus be run automatically on all subclasses of Collection.

Yes this is a bad example, have a look at TIterateTest

If you would put these test methods in CollectionTest you would have
the same result, ensuring that all subclasses satisfy the contracts of
Collection.

I think it is too easy to forget to add TEmptyTests to a new test
(especially if there are many such traits). And if somebody
intentionally avoids adding TEmptyTests, then he probably shouldn't
have subclassed Collection at all.

Pluggability.
I write one test that I can reuse in most of the tests.

I successfully use test hierarchies in Magritte and Pier from the very
beginning. This allows me to specify exact contracts in the (abstract)
superclasses that are then automatically checked on all its
subclasses. OB-RB has functionality to ensure that both class
hierarchies are identical.

Cheers,
Lukas

--
Lukas Renggli
http://www.lukas-renggli.ch

_______________________________________________
Pharo-project mailing list
[email protected]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project



_______________________________________________
Pharo-project mailing list
[email protected]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project

Reply via email to