unittest vs exceptions?

David Nadlinger see at klickverbot.at
Sat Aug 4 15:15:49 PDT 2012


On Saturday, 4 August 2012 at 22:09:03 UTC, Jonathan M Davis 
wrote:
> On Sunday, August 05, 2012 00:00:24 Maxime Chevalier wrote:
>> How does unittest check for success/failure? Does assert throw 
>> a
>> special kind of error class when it fails? How would you check
>> that some code didn't throw an exception, or did throw an
>> exception?
>
> assert throws an AssertError. The unittest failed message is 
> its message, so
> if it's never thrown, then you won't get that message. And if 
> an exception is
> thrown, then the assertion won't fail, so no AssertError will 
> be thrown, just
> the exception that your function threw.

A failed unit test really just means that a unit test block is 
left via an exception. Currently, it just bubbles up to the 
druntime main(), where it is printed to console and causes a 
non-zero exit code, but future unit test frameworks could handle 
this in a more advanced way.

David


More information about the Digitalmars-d-learn mailing list