Named unittests
Rikki Cattermole via Digitalmars-d
digitalmars-d at puremagic.com
Mon Mar 30 18:12:19 PDT 2015
On 31/03/2015 10:52 a.m., Andrei Alexandrescu wrote:
> We're having a strong need for named unittests at Facebook for multiple
> reasons.
>
> 1. We have sophisticated tooling that verifies whether unittests are
> flaky. The automated monitor (for e.g. C++) figures whether a given
> unittest fails several times across several commits. Unittests are
> identified by name; relying on file/line is impossible because the line
> of a failure is not stable across changes.
>
> 2. Again for efficient automated testing and flakiness detection, one
> should be able to run only a subset of unittests by mentioning them by
> line in the command line. Note that this implies there's no
> interdependency between distinct unittests, which is fine because the
> new ability is opt-on; I'd say is pure style anyway.
>
> 3. Mentioning unittest names in failure messages helps human
> communication (e.g. "AddPeer is failing after your change"). This is
> impossible with file and line numbers.
>
> I'd like to make a DIP for named unittests. Who can help me with that?
>
>
> Andrei
/**
* Does something funny
*
* Uses writeln, to tell the user off.
* And perhaps something else too.
*/
unittest {
import std.stdio;
import std.ddoc;
writeln("BAD USER, now say \"NO\"");
assert(readln() == "NO");
assert(ddocParse(__DDOC__).summary == "Does something funny");
}
Only one addition required. __DDOC__ to the compiler. The rest is all
library solution. Oh and assert should probably be aware of it.
void assert(bool value, string text="", string mod = __MODULE__, uint
line = __LINE__, string ddoc = __DDOC__);
Well along those lines for a prototype.
More information about the Digitalmars-d
mailing list