Compartir a través de


ExpectedExceptionBaseAttribute Class

Definition

Base class for attributes that specify to expect an exception from a unit test.

public ref class ExpectedExceptionBaseAttribute abstract : Attribute
[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple=false, Inherited=true)]
public abstract class ExpectedExceptionBaseAttribute : Attribute
[System.AttributeUsage(System.AttributeTargets.Method)]
public abstract class ExpectedExceptionBaseAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple=false, Inherited=true)>]
type ExpectedExceptionBaseAttribute = class
    inherit Attribute
[<System.AttributeUsage(System.AttributeTargets.Method)>]
type ExpectedExceptionBaseAttribute = class
    inherit Attribute
Public MustInherit Class ExpectedExceptionBaseAttribute
Inherits Attribute
Inheritance
ExpectedExceptionBaseAttribute
Derived
Attributes

Remarks

We recommend using one of the Assert.ThrowsException or Assert.ThrowsExceptionAsync overload instead of using this attribute.

Constructors

ExpectedExceptionBaseAttribute()

Initializes a new instance of the ExpectedExceptionBaseAttribute class with a default no-exception message.

ExpectedExceptionBaseAttribute(String)

Initializes a new instance of the ExpectedExceptionBaseAttribute class with a no-exception message.

Properties

NoExceptionMessage

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

SpecifiedNoExceptionMessage

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

TestContext

Methods

RethrowIfAssertException(Exception)

Rethrow the exception if it is an AssertFailedException or an AssertInconclusiveException.

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.

Applies to