Table of Contents

Method ThrowsAnyAsync

Namespace
Xunit
Assembly
xunit.v3.assert.dll

ThrowsAnyAsync<T>(Func<Task>)

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

public static Task<T> ThrowsAnyAsync<T>(Func<Task> testCode) where T : Exception

Parameters

testCode Func<Task>

A delegate to the task to be tested

Returns

Task<T>

The exception that was thrown, when successful

Type Parameters

T

The type of the exception expected to be thrown

ThrowsAnyAsync<T>(Func<Task>, Func<T, string?>)

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

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

Parameters

testCode Func<Task>

A delegate to the task 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

Task<T>

The exception that was thrown, when successful

Type Parameters

T

The type of the exception expected to be thrown