Options for unit testing in D?

Paul Backus snarwin at gmail.com
Sat Jun 22 13:51:10 UTC 2019


On Friday, 21 June 2019 at 22:35:55 UTC, Mike Brockus wrote:
> On Friday, 21 June 2019 at 17:52:43 UTC, Mike Wey wrote:
>> On 21-06-2019 06:08, Mike Brockus wrote:
>>> [...]
>>
>> If you are using the D unittests in your source you can 
>> recompile the same source with `d_unittest: true`, the 
>> appstream-generator project does this: 
>> https://github.com/ximion/appstream-generator/blob/master/src/asgen/meson.build#L108
>>
>> Or you can keep the tests separate and compile these test 
>> separately like you are doing in your C project. I use this 
>> option in the GlibD project: 
>> https://github.com/gtkd-developers/GlibD/blob/master/tests/gobject/meson.build
>
> So to use D 'unittest' I am required to include the main.d 
> module file in the tester executable?

If you pass the `-main` flag to the compiler when building your 
tester executable, it will add an empty main function for you. 
For example:

     dmd -unittest -main mymodule.d


More information about the Digitalmars-d-learn mailing list