Re: [Pharo-project] About reusing tests via traits
Stef, Dumb question: are traits essential to it, or simply a way of achieving it? Just curious, as I am still trying to put traits in perspective. They strike me (so far, right or wrong) as a form of multiple inheritance, which I have assumed (right or wrong) is often not needed with clever aggregation/composition of single-inheritance objects. One very slick use of multiple inheritance in C++ provides an easy way to implement COM objects with multiple interfaces - not that I have any desire to do that, but it is slick for C++. Whether that says something about multiple inheritance's strengths or about C++'s weaknesses, I'm not sure :) Pearls of wisdom will be eagerly assimilated. Bill Wilhelm K. Schwab, Ph.D. University of Florida Department of Anesthesiology PO Box 100254 Gainesville, FL 32610-0254 Email: bschwab@anest.ufl.edu Tel: (352) 273-6785 FAX: (352) 392-7029
stephane.ducasse@inria.fr 10/05/08 5:37 PM >>> Hi guys
I did a fun coding session in the train to brest. I started to code collection tests as traits (as damien did for stream) and this is reallllly cool. I could write some tests and apply them to OrderedCollection, Set, Bag, Interval..... I will publish that and continue. I imagine that the coverage for Collection is increase a lot. Stef _______________________________________________ Pharo-project mailing list Pharo-project@lists.gforge.inria.fr http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Traits are not essential. However they simplify the design of complex class hierarchies. Various case studies show this. Last time I use traits when coding was to share identical visit* methods in visitors that do not belong to the same class hierarchies (since they evaluate different interpreted languages). Cheers, Alexandre On 6 Oct 2008, at 03:35, Bill Schwab wrote:
Stef,
Dumb question: are traits essential to it, or simply a way of achieving it? Just curious, as I am still trying to put traits in perspective. They strike me (so far, right or wrong) as a form of multiple inheritance, which I have assumed (right or wrong) is often not needed with clever aggregation/composition of single-inheritance objects. One very slick use of multiple inheritance in C++ provides an easy way to implement COM objects with multiple interfaces - not that I have any desire to do that, but it is slick for C++. Whether that says something about multiple inheritance's strengths or about C++'s weaknesses, I'm not sure :)
Pearls of wisdom will be eagerly assimilated.
Bill
Wilhelm K. Schwab, Ph.D. University of Florida Department of Anesthesiology PO Box 100254 Gainesville, FL 32610-0254
Email: bschwab@anest.ufl.edu Tel: (352) 273-6785 FAX: (352) 392-7029
stephane.ducasse@inria.fr 10/05/08 5:37 PM >>> Hi guys
I did a fun coding session in the train to brest. I started to code collection tests as traits (as damien did for stream) and this is reallllly cool.
I could write some tests and apply them to OrderedCollection, Set, Bag, Interval..... I will publish that and continue. I imagine that the coverage for Collection is increase a lot.
Stef
_______________________________________________ Pharo-project mailing list Pharo-project@lists.gforge.inria.fr http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
_______________________________________________ Pharo-project mailing list Pharo-project@lists.gforge.inria.fr http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
-- _,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;: Alexandre Bergel http://www.bergel.eu ^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;.
you can achieve the same with copy and paste or code generation. What is nice with traits is that they represent a bloc of coherent behavior that can be parametrized. Load the latest Collection-Tests from the pharo source. This is just the start but this is quite cool. Check TEmptyTest. It is applied to OrderedCollection, Basg, Set, Array, Interval (and could be to others too). Yesterday I got a really nice presentation of Miro by alain plantec and he is also using traits. Stef On Oct 6, 2008, at 3:35 AM, Bill Schwab wrote:
Stef,
Dumb question: are traits essential to it, or simply a way of achieving it? Just curious, as I am still trying to put traits in perspective. They strike me (so far, right or wrong) as a form of multiple inheritance, which I have assumed (right or wrong) is often not needed with clever aggregation/composition of single-inheritance objects. One very slick use of multiple inheritance in C++ provides an easy way to implement COM objects with multiple interfaces - not that I have any desire to do that, but it is slick for C++. Whether that says something about multiple inheritance's strengths or about C++'s weaknesses, I'm not sure :)
Pearls of wisdom will be eagerly assimilated.
Bill
Wilhelm K. Schwab, Ph.D. University of Florida Department of Anesthesiology PO Box 100254 Gainesville, FL 32610-0254
Email: bschwab@anest.ufl.edu Tel: (352) 273-6785 FAX: (352) 392-7029
stephane.ducasse@inria.fr 10/05/08 5:37 PM >>> Hi guys
I did a fun coding session in the train to brest. I started to code collection tests as traits (as damien did for stream) and this is reallllly cool.
I could write some tests and apply them to OrderedCollection, Set, Bag, Interval..... I will publish that and continue. I imagine that the coverage for Collection is increase a lot.
Stef
_______________________________________________ Pharo-project mailing list Pharo-project@lists.gforge.inria.fr http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
_______________________________________________ Pharo-project mailing list Pharo-project@lists.gforge.inria.fr http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
represent a bloc of coherent behavior that can be parametrized. Load the latest Collection-Tests from the pharo source. This is just the start but this is quite cool. Check TEmptyTest. It is applied to OrderedCollection, Basg, Set, Array, Interval (and could be to others too).
I wonder what the advantages of using Traits over creating a test class hierarchy mirroring the collection hierarchy is? Normally the tests in TEmptyTests should be valid on all collections and should thus be run automatically on all subclasses of Collection. 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. 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
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 Pharo-project@lists.gforge.inria.fr http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
participants (4)
-
Alexandre Bergel -
Bill Schwab -
Lukas Renggli -
Stéphane Ducasse