unittest vs exceptions?

Jonathan M Davis jmdavisProg at gmx.com
Sat Aug 4 15:08:50 PDT 2012


On Sunday, August 05, 2012 00:00:24 Maxime Chevalier wrote:
> I'd like to write some unit tests to check my software. Writing
> unittest blocks and putting assert statements in there seems easy
> enough, but I noticed that if the code I run in there throws an
> exception, I don't get the unit test failed message.
> 
> 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.

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list