If -unittest
flag is passed to the D compiler, it will run all unittest blocks. Often it is useful to let the compiler generate a stubbed main
function. Using the compile & run wrapper rdmd
, testing your D program gets as easy as:
rdmd -main -unittest yourcode.d
Of course you can also split this process into two steps if you want:
dmd -main -unittest yourcode.d
./yourcode
For dub
projects compiling all files and executing their unittest blocks can be done conveniently with
dub test
alias tdmd="rdmd -main -unittest"
and then test your files with:
tdmd yourcode.d