DUnit - class MyTest { mixin TestMixin; void testMethod1() {} void testMethod2() {}}

Juan Manuel Cabo juanmanuel.cabo at gmail.com
Sun Feb 19 07:30:31 PST 2012


People of the D world.. I give you DUnit (not to be confused with 
an old
tango DUnit, this one is for >= D2.057, and doesn't really 
require phobos or tango (just you version the few writeln's of 
the runner, and maybe
something else)).

       https://github.com/jmcabo/dunit

I've been developing it for the past few weeks, and since I saw a 
post of another unit testing framework just a few minutes ago, I 
thought I'd rush it to github.

Soooo, here is how you define a test:


import dunit;

class Something {
     mixin TestMixin;

     void testOne() {
         assert(1 == 1, "this works");
     }

     void testTwo() {
         assertEquals(1, 2/2);
         assertEquals("a string", "a"~" string");
     }
}

.. and that's all there is to it. Put the mixin TestMixin, and 
name your tests
starting with 'test'. The results output shows all of them even 
if some fail, and... guess what, it tells you the name of the 
unit tests that failed!! isn't this awesome!! (all thanks to 
mixins, recursive template declarations, __traits, and a little 
bit of CTFE)... isn't D like, so incredibly awesome or what!?!?

There is absolutely no overhead in registering the tests for the 
test runner.. its all at compile time!

Your tests are inherited through derived classes, and can be 
private in the unit test class (they will still run).


I made two test runners:

     * One that shows the results in java style (but WITH COLORS!! 
(fineprint: colors only on unix console, windows console is 
colorless for now)

     * Another one more verbose that shows the tree of tests as it 
runs them.

It is very easy to make your own.


This is all BOOST licenced, so please tweak it away!


FINEPRINT yes shouting fineprint ;-) haha:
THIS IS NOT A unitest{} REPLACEMENT, JUST AN ITCH EVERY OOP 
PEOPLE WANTED TO SCRATCH: named, easy, xUnit style unit tests.. 
AND NOW YOU'VE GOT THEM.






More information about the Digitalmars-d-announce mailing list