Table of Contents

Method ThrowsAny

Namespace
Xunit
Assembly
xunit.v3.assert.dll

ThrowsAny<T>(Action)

Verifies that the exact exception or a derived exception type is thrown.

public static T ThrowsAny<T>(Action testCode) where T : Exception

Parameters

testCode Action

A delegate to the code to be tested

Returns

T

The exception that was thrown, when successful

Type Parameters

T

The type of the exception expected to be thrown

ThrowsAny<T>(Action, Func<T, string?>)

Verifies that the exact exception or a derived exception type is thrown.

public static T ThrowsAny<T>(Action testCode, Func<T, string?> inspector) where T : Exception

Parameters

testCode Action

A delegate to the code to be tested

inspector Func<T, string>

A function which inspects the exception to determine if it's valid or not. Returns null if the exception is valid, or a message if it's not.

Returns

T

The exception that was thrown, when successful

Type Parameters

T

The type of the exception expected to be thrown

ThrowsAny<T>(Func<object?>)

Verifies that the exact exception or a derived exception type is thrown. Generally used to test property accessors.

public static T ThrowsAny<T>(Func<object?> testCode) where T : Exception

Parameters

testCode Func<object>

A delegate to the code to be tested

Returns

T

The exception that was thrown, when successful

Type Parameters

T

The type of the exception expected to be thrown

ThrowsAny<T>(Func<object?>, Func<T, string?>)

Verifies that the exact exception or a derived exception type is thrown. Generally used to test property accessors.

public static T ThrowsAny<T>(Func<object?> testCode, Func<T, string?> inspector) where T : Exception

Parameters

testCode Func<object>

A delegate to the code to be tested

inspector Func<T, string>

A function which inspects the exception to determine if it's valid or not. Returns null if the exception is valid, or a message if it's not.

Returns

T

The exception that was thrown, when successful

Type Parameters

T

The type of the exception expected to be thrown