All About xUnit
Testing Exceptions
When the code under test is expected to throw an exception,
the test must include special handling.
Otherwise, the test would terminate abnormally, whereas it should really pass
if the exception is thrown as designed.In most situations, the easy way needs very little code to checks for an exception.Call the code under the test with no special try-catch handling. Instead,
use the test must include special handling.
ASSERT_THROW
to assert on the specific exception,
or ASSERT_ANY_THROW
to check that any exception is thrown:
(Reading...)
Formatting Hints:
To format... | use this markup: |
---|---|
source code | {source:lang=java|lineNumbers=false}...{source} (Supported languages: java, cpp, csharp, c, python.) |
bold text | __some text__ |
italicized text | ~~some text~~ |
underlined text | @@some text@@ |
a method or class name | ``myMethod(...)`` |