Can one customize unit tests?

Dennis dkorpel at
Sat Aug 3 14:38:11 UTC 2019

The out-of-the box unittest runner is pretty bare by design. It 
just runs unittest blocks in serial as functions where assert() 
failures are not undefined behavior. Assert messages are not very 
helpful, though the recently added flag `-checkaction=context` 
helps a lot.

Luckily there is a trait for getting unittests:

So it is possible to make your own unittest runner, as people 
have done:

On Saturday, 3 August 2019 at 13:31:02 UTC, PV wrote:
> Is it possible to somehow customize syntax and running of unit 
> tests?

You can add @("attributes") to your unittests.
The default test-runner will not do anything with them currently, 
but your own test runner can.

> I'd looked into the documentation, found nothing, but perhaps I 
> just missed it. If it is not possible, is it realistic to (very 
> easily) hack the D compiler to implement such feature?

Shouldn't be necessary, I think what you want can be done with 
attributes and your own test runner.

> Would such feature also work in betterC?

unittest blocks itself are supported in betterC, so you can 
probably make it work.

More information about the Digitalmars-d-learn mailing list