Method Throws
- Namespace
- Xunit
- Assembly
- xunit.v3.assert.dll
Throws(Type, Action)
Verifies that the exact exception is thrown (and not a derived exception type).
public static Exception Throws(Type exceptionType, Action testCode)
Parameters
exceptionTypeTypeThe type of the exception expected to be thrown
testCodeActionA delegate to the code to be tested
Returns
- Exception
The exception that was thrown, when successful
Throws(Type, Func<object?>)
Verifies that the exact exception is thrown (and not a derived exception type). Generally used to test property accessors.
public static Exception Throws(Type exceptionType, Func<object?> testCode)
Parameters
exceptionTypeTypeThe type of the exception expected to be thrown
testCodeFunc<object>A delegate to the code to be tested
Returns
- Exception
The exception that was thrown, when successful
Throws<T>(Action)
Verifies that the exact exception is thrown (and not a derived exception type).
public static T Throws<T>(Action testCode) where T : Exception
Parameters
testCodeActionA delegate to the code to be tested
Returns
- T
The exception that was thrown, when successful
Type Parameters
TThe type of the exception expected to be thrown
Throws<T>(Func<object?>)
Verifies that the exact exception is thrown (and not a derived exception type). Generally used to test property accessors.
public static T Throws<T>(Func<object?> testCode) where T : Exception
Parameters
Returns
- T
The exception that was thrown, when successful
Type Parameters
TThe type of the exception expected to be thrown
Throws<T>(string?, Action)
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 T Throws<T>(string? paramName, Action testCode) where T : ArgumentException
Parameters
paramNamestringThe parameter name that is expected to be in the exception
testCodeActionA delegate to the code to be tested
Returns
- T
The exception that was thrown, when successful
Type Parameters
T
Throws<T>(string?, Func<object?>)
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 T Throws<T>(string? paramName, Func<object?> testCode) where T : ArgumentException
Parameters
paramNamestringThe parameter name that is expected to be in the exception
testCodeFunc<object>A delegate to the code to be tested
Returns
- T
The exception that was thrown, when successful
Type Parameters
T