About unittest, test runners and assert libraries

Andre Pany andre at s-e-a-p.de
Wed May 12 21:23:08 UTC 2021


On Wednesday, 12 May 2021 at 18:52:13 UTC, Zardoz wrote:
> On Monday, 10 May 2021 at 17:45:03 UTC, Andre Pany wrote:
>> On Monday, 10 May 2021 at 17:20:54 UTC, Zardoz wrote:
>>> I like to talk about the state of unit testing, test runner & 
>>> frameworks and assert libraries, as I did some little 
>>> experiments recently.
>>>
>>> [...]
>>
>> Just some comments regarding D-Unit:
>>
>> You can run it just using `dub test` by using a dub 
>> configuration `unittest`.
>>
>> If I am not completely wrong it does not ignore `unittest` 
>> blocks. It shows the result of the unittest blocks in the 
>> output.
>>
>> You use asserts in your productive logic for program errors, 
>> therefore it make sense that D-Unit Mark's them as errors. 
>> (For resource errors on the other hand you use Exceptions).
>>
>> Kind regards
>> Andre
>
> It just ignores the unit test blocks, You can try here : 
> https://github.com/Zardoz89/pijamas/tree/develop
>
> Launch with dub run --root=tests/d-unit
> Also, you can launch with dub run --root=tests/d-unit -c 
> fail-tests to enable enforce some failing/errors on the test 
> cases.
>
> Also, I try again with dub test . It just executes the dlang 
> default unit test runner. Perhaps I have something wrong on 
> dub.json

You need to add to dub.json a configuration with name "unittest". 
Within this configuration you set "mainSourceFile" to "apptest.d" 
and you need to exclude you module containing the productive main 
function.

In apptest.d you add a main function and call the dunit_main 
function.

Dub test will cause the right compiler flags to have unittests 
included into your executable. By just using dub run, your 
executable likely does not have the unittests.

Kind regards
Andre


More information about the Digitalmars-d mailing list