Testing D codes

drug via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Apr 10 23:54:17 PDT 2017


10.04.2017 19:20, Russel Winder via Digitalmars-d-learn пишет:
> On Fri, 2017-04-07 at 11:40 +0300, drug via Digitalmars-d-learn wrote:
>>
> […]
>> I do this. I have unittests in the module sources and have a
>> separate
>> subpackage intended for more advanced testing only.
>
> Do you have an example project I could take a look at?
>
Unfortunately it's proprietary code. It's like this:
```
module tests;

import std.datetime: dur;
import core.thread: Thread;

import unit_threaded.runner;
import unit_threaded: TestCase, shouldEqual;

class Fixture: TestCase
{
     override void setup()
     {
	// do common things for derived test
     }
}

class TestToiDataSerialization: Fixture
{
     override void test()
     {
         // the test, is using setup() of the fixture above
     }
}

class TestCommandMessageSerialization: Fixture
{
     override void test()
     {
         // and so on
     }
}

class TestNetworking: Fixture
{
     override void test()
     {
         // and so on
     }
}

int main(string[] args)
{
     import std.experimental.logger: LogLevel, globalLogLevel;

     try
     {
         globalLogLevel = LogLevel.fatal;

         return args.runTests!(
             "tests", // run all tests (three in this case) of the 
`tests` module (this module)
         );
     }
     catch(Exception e)
     {
         import std.stdio: stderr;
         stderr.writeln(e.msg);
         return 1;
     }
}
```
You can place some tests in other module, then this module should be 
added to runner.


More information about the Digitalmars-d-learn mailing list