Table of Contents

Method ThrowsAsync

Namespace
Xunit
Assembly
xunit.v3.assert.dll

ThrowsAsync(Type, Func<Task>)

Verifies that the exact exception is thrown (and not a derived exception type).

public static Task<Exception> ThrowsAsync(Type exceptionType, Func<Task> testCode)

Parameters

exceptionType Type

The type of the exception expected to be thrown

testCode Func<Task>

A delegate to the task to be tested

Returns

Task<Exception>

The exception that was thrown, when successful

ThrowsAsync<T>(Func<Task>)

Verifies that the exact exception is thrown (and not a derived exception type).

public static Task<T> ThrowsAsync<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

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

Verifies that the exact exception is thrown (and not a derived exception type), where the exception derives from ArgumentException and has the given parameter name.

public static Task<T> ThrowsAsync<T>(string? paramName, Func<Task> testCode) where T : ArgumentException

Parameters

paramName string

The parameter name that is expected to be in the exception

testCode Func<Task>

A delegate to the task to be tested

Returns

Task<T>

The exception that was thrown, when successful

Type Parameters

T