Pex - Automated Whitebox Testing for .NET : Allowing Exceptions

Allowing Exceptions

Pex provides numerous ways to help triaging exception into expected exceptions and unexpected exceptions.

Expected exceptions generate negative test cases with the appropriate annotation (i.e. ExpectedException(typeof(xxx))), while unexpected exceptions generate failing unit test cases.

All validation attributes inherit from the PexAllowedExceptionAttributeBase and are used as regular exception decorators:

[PexMethod, PexAllowedException(typeof(ArgumentNullException))]
void SomeTest() {...}

Other validators are:

Common settings

  • AcceptExceptionSubtypes, determines whether subtypes of the allowed exception are valid,
  • AcceptInnerExceptions, determines whether the exception chain should be walked to find a valid instance,
  • Documented, determines whether the exception type should be documented in the xml documentation of the target site method,
(c) Microsoft Corporation. All rights reserved. pex Wiki Documentation 0.93.50813.0