Share via


ExpectedExceptionAttribute Class

Definition

Attribute that specifies to expect an exception of the specified type

public ref class ExpectedExceptionAttribute sealed : Microsoft::VisualStudio::TestTools::UnitTesting::ExpectedExceptionBaseAttribute
[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple=false, Inherited=true)]
public sealed class ExpectedExceptionAttribute : Microsoft.VisualStudio.TestTools.UnitTesting.ExpectedExceptionBaseAttribute
[<System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple=false, Inherited=true)>]
type ExpectedExceptionAttribute = class
    inherit ExpectedExceptionBaseAttribute
Public NotInheritable Class ExpectedExceptionAttribute
Inherits ExpectedExceptionBaseAttribute
Inheritance
ExpectedExceptionAttribute
Attributes

Constructors

ExpectedExceptionAttribute(Type, String)

Initializes a new instance of the ExpectedExceptionAttribute class with the expected type and the message to include when no exception is thrown by the test.

ExpectedExceptionAttribute(Type)

Initializes a new instance of the ExpectedExceptionAttribute class with the expected type

Properties

AllowDerivedTypes

Gets or sets a value indicating whether to allow types derived from the type of the expected exception to qualify as expected

ExceptionType

Gets a value indicating the Type of the expected exception

NoExceptionMessage

Gets the message to include in the test result if the test fails due to not throwing an exception

(Inherited from ExpectedExceptionBaseAttribute)
SpecifiedNoExceptionMessage

Gets the message to include in the test result if the test fails due to not throwing an exception

(Inherited from ExpectedExceptionBaseAttribute)
TestContext (Inherited from ExpectedExceptionBaseAttribute)

Methods

RethrowIfAssertException(Exception)

Rethrow the exception if it is an AssertFailedException or an AssertInconclusiveException

(Inherited from ExpectedExceptionBaseAttribute)
Verify(Exception)

Determines whether the exception is expected. If the method returns, then it is understood that the exception was expected. If the method throws an exception, then it is understood that the exception was not expected, and the thrown exception's message is included in the test result. The Assert class can be used for convenience. If Inconclusive() is used and the assertion fails, then the test outcome is set to Inconclusive.

(Inherited from ExpectedExceptionBaseAttribute)

Applies to