Parallel execution of unittests

Johannes Pfau via Digitalmars-d digitalmars-d at puremagic.com
Wed Apr 30 09:48:45 PDT 2014


Am Wed, 30 Apr 2014 09:28:18 -0700
schrieb Andrei Alexandrescu <SeeWebsiteForEmail at erdani.org>:

> > I also wonder if its just better to extend/expose the unittest API
> > for more advanced things like order of execution, test reporting,
> > and parallel execution. And we can just support an external
> > unittesting library to do all the advanced testing options.  
> 
> That would be pretty rad.

We can kinda do that.
I guess the main problem for a simple approach is that unittests are
functions but advanced frameworks often have unittest classes/objects.
We can't really emulate that on top of functions.

What we can easily do is parse UDAs on unittests and provide access to
these UDAs. For example:

------------
module my.testlib;

struct Author
{
    string _name;
    string serialize() {return _name;} //Must be evaluated in CTFE
}
------------
module test;

import my.testlib;
@Author("The Author") unittest
{
    //Code goes here
}
------------

Then with the mentioned pull request we just add another field to the
runtime unittest information struct: An associative array with string
keys matching the qualified name of the UDA and as values the strings
returned by serialize() (evaluated by CTFE).

Then we have for the test runner:
------------
foreach( m; ModuleInfo )
{
    foreach(test; m.unitTests)
    {
        if("my.testlib.Author" in test.uda)
            writefln("Author: %s", test.uda["my.testlib.Author"]);
    }
}
------------

This is some more work to implement though, but it's additive so we can
first implement the basic mechanism in pull #1131 then add this uda
stuff later.


More information about the Digitalmars-d mailing list