unittesting generic functions

Walter Bright via Digitalmars-d digitalmars-d at puremagic.com
Thu Aug 14 13:25:35 PDT 2014


On 8/13/2014 9:02 PM, H. S. Teoh via Digitalmars-d wrote:
> 4) How much can you realistically test on a generic type argument T,
> that you can't already cover with concrete types? I'm finding that the
> per-instantiation behaviour of unittest blocks inside templated
> structs/classes is rarely desired, esp. when you write ddoc unittests
> (because you want code examples in the docs to involve concrete types,
> not abstract types, otherwise they are of limited use to the reader).
> Because of this, I often move unittests outside the aggregate or enclose
> them in static if's. This suggests that perhaps per-instantiation
> unittests are only of limited utility.

Just to expand on this, one of the great advantages of template functions and 
separate unittests is the unittest can instantiate the template function with 
"mocked up" arguments. Instantiating the unittest for every type passed to it 
would defeat that method.



More information about the Digitalmars-d mailing list