Search Results for

    Show / Hide Table of Contents

    Class Assert

    The Assert class contains a collection of static methods that implement the most common assertions used in NUnit.

    Inheritance
    object
    AssertBase
    Assert
    ClassicAssert
    Inherited Members
    AssertBase.ConvertMessageWithArgs(string, object[])
    object.GetType()
    object.MemberwiseClone()
    object.ToString()
    object.Equals(object)
    object.Equals(object, object)
    object.ReferenceEquals(object, object)
    object.GetHashCode()
    Namespace: NUnit.Framework
    Assembly: nunit.framework.dll
    Syntax
    public abstract class Assert : AssertBase

    Constructors

    View Source

    Assert()

    Declaration
    protected Assert()

    Methods

    View Source

    ByVal(object?, IResolveConstraint, string, string, string)

    Apply a constraint to an actual value. Returns without throwing an exception when inside a multiple assert block. Used as a synonym for That in rare cases where a private setter causes a Visual Basic compilation error.

    Declaration
    public static void ByVal(object? actual, IResolveConstraint expression, string message = "", string actualExpression = "", string constraintExpression = "")
    Parameters
    Type Name Description
    object actual

    The actual value to test

    IResolveConstraint expression

    A Constraint expression to be applied

    string message

    The message that will be displayed on failure

    string actualExpression
    string constraintExpression
    Remarks

    This method is provided for use by VB developers needing to test the value of properties with private setters.

    View Source

    Catch(TestDelegate)

    Verifies that a delegate throws an exception when called and returns it. The returned exception may be null when inside a multiple assert block.

    Declaration
    public static Exception? Catch(TestDelegate code)
    Parameters
    Type Name Description
    TestDelegate code

    A TestDelegate

    Returns
    Type Description
    Exception
    View Source

    Catch(TestDelegate, string, params object?[]?)

    Verifies that a delegate throws an exception when called and returns it. The returned exception may be null when inside a multiple assert block.

    Declaration
    public static Exception? Catch(TestDelegate code, string message, params object?[]? args)
    Parameters
    Type Name Description
    TestDelegate code

    A TestDelegate

    string message

    The message that will be displayed on failure

    object[] args

    Arguments to be used in formatting the message

    Returns
    Type Description
    Exception
    View Source

    Catch(Type, TestDelegate)

    Verifies that a delegate throws an exception of a certain Type or one derived from it when called and returns it. The returned exception may be null when inside a multiple assert block.

    Declaration
    public static Exception? Catch(Type expectedExceptionType, TestDelegate code)
    Parameters
    Type Name Description
    Type expectedExceptionType

    The expected Exception Type

    TestDelegate code

    A TestDelegate

    Returns
    Type Description
    Exception
    View Source

    Catch(Type, TestDelegate, string, params object?[]?)

    Verifies that a delegate throws an exception of a certain Type or one derived from it when called and returns it. The returned exception may be null when inside a multiple assert block.

    Declaration
    public static Exception? Catch(Type expectedExceptionType, TestDelegate code, string message, params object?[]? args)
    Parameters
    Type Name Description
    Type expectedExceptionType

    The expected Exception Type

    TestDelegate code

    A TestDelegate

    string message

    The message that will be displayed on failure

    object[] args

    Arguments to be used in formatting the message

    Returns
    Type Description
    Exception
    View Source

    CatchAsync(AsyncTestDelegate)

    Verifies that an async delegate throws an exception when called and returns it. The returned exception may be null when inside a multiple assert block.

    Declaration
    public static Exception? CatchAsync(AsyncTestDelegate code)
    Parameters
    Type Name Description
    AsyncTestDelegate code

    A TestDelegate

    Returns
    Type Description
    Exception
    View Source

    CatchAsync(AsyncTestDelegate, string, params object?[]?)

    Verifies that an async delegate throws an exception when called and returns it. The returned exception may be null when inside a multiple assert block.

    Declaration
    public static Exception? CatchAsync(AsyncTestDelegate code, string message, params object?[]? args)
    Parameters
    Type Name Description
    AsyncTestDelegate code

    A TestDelegate

    string message

    The message that will be displayed on failure

    object[] args

    Arguments to be used in formatting the message

    Returns
    Type Description
    Exception
    View Source

    CatchAsync(Type, AsyncTestDelegate)

    Verifies that an async delegate throws an exception of a certain Type or one derived from it when called and returns it. The returned exception may be null when inside a multiple assert block.

    Declaration
    public static Exception? CatchAsync(Type expectedExceptionType, AsyncTestDelegate code)
    Parameters
    Type Name Description
    Type expectedExceptionType

    The expected Exception Type

    AsyncTestDelegate code

    A TestDelegate

    Returns
    Type Description
    Exception
    View Source

    CatchAsync(Type, AsyncTestDelegate, string, params object?[]?)

    Verifies that an async delegate throws an exception of a certain Type or one derived from it when called and returns it. The returned exception may be null when inside a multiple assert block.

    Declaration
    public static Exception? CatchAsync(Type expectedExceptionType, AsyncTestDelegate code, string message, params object?[]? args)
    Parameters
    Type Name Description
    Type expectedExceptionType

    The expected Exception Type

    AsyncTestDelegate code

    A TestDelegate

    string message

    The message that will be displayed on failure

    object[] args

    Arguments to be used in formatting the message

    Returns
    Type Description
    Exception
    View Source

    CatchAsync<TActual>(AsyncTestDelegate)

    Verifies that an async delegate throws an exception of a certain Type or one derived from it when called and returns it. The returned exception may be null when inside a multiple assert block.

    Declaration
    public static TActual? CatchAsync<TActual>(AsyncTestDelegate code) where TActual : Exception
    Parameters
    Type Name Description
    AsyncTestDelegate code

    A TestDelegate

    Returns
    Type Description
    TActual
    Type Parameters
    Name Description
    TActual
    View Source

    CatchAsync<TActual>(AsyncTestDelegate, string, params object?[]?)

    Verifies that an async delegate throws an exception of a certain Type or one derived from it when called and returns it. The returned exception may be null when inside a multiple assert block.

    Declaration
    public static TActual? CatchAsync<TActual>(AsyncTestDelegate code, string message, params object?[]? args) where TActual : Exception
    Parameters
    Type Name Description
    AsyncTestDelegate code

    A TestDelegate

    string message

    The message that will be displayed on failure

    object[] args

    Arguments to be used in formatting the message

    Returns
    Type Description
    TActual
    Type Parameters
    Name Description
    TActual
    View Source

    Catch<TActual>(TestDelegate)

    Verifies that a delegate throws an exception of a certain Type or one derived from it when called and returns it. The returned exception may be null when inside a multiple assert block.

    Declaration
    public static TActual? Catch<TActual>(TestDelegate code) where TActual : Exception
    Parameters
    Type Name Description
    TestDelegate code

    A TestDelegate

    Returns
    Type Description
    TActual
    Type Parameters
    Name Description
    TActual
    View Source

    Catch<TActual>(TestDelegate, string, params object?[]?)

    Verifies that a delegate throws an exception of a certain Type or one derived from it when called and returns it. The returned exception may be null when inside a multiple assert block.

    Declaration
    public static TActual? Catch<TActual>(TestDelegate code, string message, params object?[]? args) where TActual : Exception
    Parameters
    Type Name Description
    TestDelegate code

    A TestDelegate

    string message

    The message that will be displayed on failure

    object[] args

    Arguments to be used in formatting the message

    Returns
    Type Description
    TActual
    Type Parameters
    Name Description
    TActual
    View Source

    Charlie()

    An alias of the corresponding Assert.Pass() method. Charlie Poole was the lead of NUnit for 21 years, across at least 207 releases in 37 different repositories, authoring 4,898 commits across them. He participated in 2,990 issues, 1,305 PRs, and impacted 6,992,983 lines of code. NUnit was downloaded from NuGet 225+ million times during his tenure. And those are only the numbers ones we can easily find; our numbers are sourced from after NUnit moved the project to GitHub in 2011, which means there are at least 9 additional years of work not quantified above.

    This assertion attempts to pay homage to Charlie, who by virtue of his contributions has helped untold millions of tests pass.

    Declaration
    public static void Charlie()
    View Source

    DoesNotThrow(TestDelegate)

    Verifies that a delegate does not throw an exception.

    Declaration
    public static void DoesNotThrow(TestDelegate code)
    Parameters
    Type Name Description
    TestDelegate code

    A TestDelegate

    View Source

    DoesNotThrow(TestDelegate, string, params object?[]?)

    Verifies that a delegate does not throw an exception

    Declaration
    public static void DoesNotThrow(TestDelegate code, string message, params object?[]? args)
    Parameters
    Type Name Description
    TestDelegate code

    A TestDelegate

    string message

    The message that will be displayed on failure

    object[] args

    Arguments to be used in formatting the message

    View Source

    DoesNotThrowAsync(AsyncTestDelegate)

    Verifies that an async delegate does not throw an exception.

    Declaration
    public static void DoesNotThrowAsync(AsyncTestDelegate code)
    Parameters
    Type Name Description
    AsyncTestDelegate code

    A TestDelegate

    View Source

    DoesNotThrowAsync(AsyncTestDelegate, string, params object?[]?)

    Verifies that an async delegate does not throw an exception

    Declaration
    public static void DoesNotThrowAsync(AsyncTestDelegate code, string message, params object?[]? args)
    Parameters
    Type Name Description
    AsyncTestDelegate code

    A TestDelegate

    string message

    The message that will be displayed on failure

    object[] args

    Arguments to be used in formatting the message

    View Source

    EnterMultipleScope()

    Enters a multiple assert scope. Wraps code containing a series of assertions, which should all be executed, even if they fail. Failed results are saved and reported when the returned IDisposable is disposed.

    Declaration
    public static IDisposable EnterMultipleScope()
    Returns
    Type Description
    IDisposable

    An IDisposable which when disposed leaves the multiple assertion scope.

    View Source

    Fail()

    Marks the test as failed. Returns without throwing an exception when inside a multiple assert block.

    Declaration
    public static void Fail()
    View Source

    Fail(string)

    Marks the test as failed with the message and arguments that are passed in. Returns without throwing an exception when inside a multiple assert block.

    Declaration
    public static void Fail(string message)
    Parameters
    Type Name Description
    string message

    The message to initialize the AssertionException with.

    View Source

    Ignore()

    Throws an IgnoreException. This causes the test to be reported as ignored.

    Declaration
    public static void Ignore()
    View Source

    Ignore(string)

    Throws an IgnoreException with the message and arguments that are passed in. This causes the test to be reported as ignored.

    Declaration
    public static void Ignore(string message)
    Parameters
    Type Name Description
    string message

    The message to initialize the AssertionException with.

    View Source

    Inconclusive()

    Throws an InconclusiveException. This causes the test to be reported as Inconclusive.

    Declaration
    public static void Inconclusive()
    View Source

    Inconclusive(string)

    Throws an InconclusiveException with the message and arguments that are passed in. This causes the test to be reported as inconclusive.

    Declaration
    public static void Inconclusive(string message)
    Parameters
    Type Name Description
    string message

    The message to initialize the InconclusiveException with.

    View Source

    Multiple(AsyncTestDelegate)

    Wraps code containing a series of assertions, which should all be executed, even if they fail. Failed results are saved and reported at the end of the code block.

    Declaration
    public static void Multiple(AsyncTestDelegate testDelegate)
    Parameters
    Type Name Description
    AsyncTestDelegate testDelegate

    A TestDelegate to be executed in Multiple Assertion mode.

    View Source

    Multiple(TestDelegate)

    Wraps code containing a series of assertions, which should all be executed, even if they fail. Failed results are saved and reported at the end of the code block.

    Declaration
    public static void Multiple(TestDelegate testDelegate)
    Parameters
    Type Name Description
    TestDelegate testDelegate

    A TestDelegate to be executed in Multiple Assertion mode.

    View Source

    MultipleAsync(AsyncTestDelegate)

    Wraps code containing a series of assertions, which should all be executed, even if they fail. Failed results are saved and reported at the end of the code block.

    Declaration
    public static Task MultipleAsync(AsyncTestDelegate testDelegate)
    Parameters
    Type Name Description
    AsyncTestDelegate testDelegate

    An AsyncTestDelegate to be executed in Multiple Assertion mode.

    Returns
    Type Description
    Task
    View Source

    Pass()

    Throws a SuccessException with the message and arguments that are passed in. This allows a test to be cut short, with a result of success returned to NUnit.

    Declaration
    public static void Pass()
    View Source

    Pass(string)

    Throws a SuccessException with the message and arguments that are passed in. This allows a test to be cut short, with a result of success returned to NUnit.

    Declaration
    public static void Pass(string message)
    Parameters
    Type Name Description
    string message

    The message to initialize the AssertionException with.

    View Source

    That(TestDelegate, IResolveConstraint, NUnitString, string, string)

    Apply a constraint to a delegate. Returns without throwing an exception when inside a multiple assert block.

    Declaration
    public static void That(TestDelegate code, IResolveConstraint constraint, NUnitString message = default, string actualExpression = "", string constraintExpression = "")
    Parameters
    Type Name Description
    TestDelegate code

    A TestDelegate to be executed

    IResolveConstraint constraint

    A Constraint expression to be applied

    NUnitString message

    The message that will be displayed on failure

    string actualExpression
    string constraintExpression
    View Source

    That(TestDelegate, IResolveConstraint, FormattableString, string, string)

    Apply a constraint to a delegate. Returns without throwing an exception when inside a multiple assert block.

    Declaration
    public static void That(TestDelegate code, IResolveConstraint constraint, FormattableString message, string actualExpression = "", string constraintExpression = "")
    Parameters
    Type Name Description
    TestDelegate code

    A TestDelegate to be executed

    IResolveConstraint constraint

    A Constraint expression to be applied

    FormattableString message

    The message that will be displayed on failure

    string actualExpression
    string constraintExpression
    View Source

    That(TestDelegate, IResolveConstraint, Func<string>, string, string)

    Apply a constraint to a delegate. Returns without throwing an exception when inside a multiple assert block.

    Declaration
    public static void That(TestDelegate code, IResolveConstraint constraint, Func<string> getExceptionMessage, string actualExpression = "", string constraintExpression = "")
    Parameters
    Type Name Description
    TestDelegate code

    A TestDelegate to be executed

    IResolveConstraint constraint

    A Constraint expression to be applied

    Func<string> getExceptionMessage

    A function to build the message included with the Exception

    string actualExpression
    string constraintExpression
    View Source

    That(bool, NUnitString, string)

    Asserts that a condition is true. Returns without throwing an exception when inside a multiple assert block.

    Declaration
    public static void That(bool condition, NUnitString message = default, string actualExpression = "")
    Parameters
    Type Name Description
    bool condition

    The evaluated condition

    NUnitString message

    The message to display if the condition is false

    string actualExpression
    View Source

    That(bool, FormattableString, string)

    Asserts that a condition is true. Returns without throwing an exception when inside a multiple assert block.

    Declaration
    public static void That(bool condition, FormattableString message, string actualExpression = "")
    Parameters
    Type Name Description
    bool condition

    The evaluated condition

    FormattableString message

    The message to display if the condition is false

    string actualExpression
    View Source

    That(bool, Func<string>, string)

    Asserts that a condition is true. Returns without throwing an exception when inside a multiple assert block.

    Declaration
    public static void That(bool condition, Func<string> getExceptionMessage, string actualExpression = "")
    Parameters
    Type Name Description
    bool condition

    The evaluated condition

    Func<string> getExceptionMessage

    A function to build the message included with the Exception

    string actualExpression
    View Source

    That(Func<bool>, NUnitString, string)

    Asserts that a condition is true. Returns without throwing an exception when inside a multiple assert block.

    Declaration
    public static void That(Func<bool> condition, NUnitString message = default, string actualExpression = "")
    Parameters
    Type Name Description
    Func<bool> condition

    A lambda that returns a Boolean

    NUnitString message

    The message to display if the condition is false

    string actualExpression
    View Source

    That(Func<bool>, FormattableString, string)

    Asserts that a condition is true. Returns without throwing an exception when inside a multiple assert block.

    Declaration
    public static void That(Func<bool> condition, FormattableString message, string actualExpression = "")
    Parameters
    Type Name Description
    Func<bool> condition

    A lambda that returns a Boolean

    FormattableString message

    The message to display if the condition is false

    string actualExpression
    View Source

    That(Func<bool>, Func<string>, string)

    Asserts that a condition is true. Returns without throwing an exception when inside a multiple assert block.

    Declaration
    public static void That(Func<bool> condition, Func<string> getExceptionMessage, string actualExpression = "")
    Parameters
    Type Name Description
    Func<bool> condition

    A lambda that returns a Boolean

    Func<string> getExceptionMessage

    A function to build the message included with the Exception

    string actualExpression
    View Source

    ThatAsync(AsyncTestDelegate, IResolveConstraint, NUnitString, string, string)

    Apply a constraint to an async delegate. Returns without throwing an exception when inside a multiple assert block.

    Declaration
    public static Task ThatAsync(AsyncTestDelegate code, IResolveConstraint constraint, NUnitString message = default, string actualExpression = "", string constraintExpression = "")
    Parameters
    Type Name Description
    AsyncTestDelegate code

    An AsyncTestDelegate to be executed

    IResolveConstraint constraint

    A Constraint expression to be applied

    NUnitString message

    The message that will be displayed on failure

    string actualExpression
    string constraintExpression
    Returns
    Type Description
    Task

    Awaitable.

    View Source

    ThatAsync(AsyncTestDelegate, IResolveConstraint, FormattableString, string, string)

    Apply a constraint to an async delegate. Returns without throwing an exception when inside a multiple assert block.

    Declaration
    public static Task ThatAsync(AsyncTestDelegate code, IResolveConstraint constraint, FormattableString message, string actualExpression = "", string constraintExpression = "")
    Parameters
    Type Name Description
    AsyncTestDelegate code

    An AsyncTestDelegate to be executed

    IResolveConstraint constraint

    A Constraint expression to be applied

    FormattableString message

    The message that will be displayed on failure

    string actualExpression
    string constraintExpression
    Returns
    Type Description
    Task

    Awaitable.

    View Source

    ThatAsync<T>(Func<Task<T>>, IResolveConstraint, NUnitString, string, string)

    Apply a constraint to an async delegate. Returns without throwing an exception when inside a multiple assert block.

    Declaration
    public static Task ThatAsync<T>(Func<Task<T>> code, IResolveConstraint constraint, NUnitString message = default, string actualExpression = "", string constraintExpression = "")
    Parameters
    Type Name Description
    Func<Task<T>> code

    An async method to be executed

    IResolveConstraint constraint

    A Constraint expression to be applied

    NUnitString message

    The message that will be displayed on failure

    string actualExpression
    string constraintExpression
    Returns
    Type Description
    Task

    Awaitable.

    Type Parameters
    Name Description
    T
    View Source

    ThatAsync<T>(Func<Task<T>>, IResolveConstraint, FormattableString, string, string)

    Apply a constraint to an async delegate. Returns without throwing an exception when inside a multiple assert block.

    Declaration
    public static Task ThatAsync<T>(Func<Task<T>> code, IResolveConstraint constraint, FormattableString message, string actualExpression = "", string constraintExpression = "")
    Parameters
    Type Name Description
    Func<Task<T>> code

    An async method to be executed

    IResolveConstraint constraint

    A Constraint expression to be applied

    FormattableString message

    The message that will be displayed on failure

    string actualExpression
    string constraintExpression
    Returns
    Type Description
    Task

    Awaitable.

    Type Parameters
    Name Description
    T
    View Source

    That<TActual>(ActualValueDelegate<TActual>, IResolveConstraint, NUnitString, string, string)

    Apply a constraint to a delegate. Returns without throwing an exception when inside a multiple assert block.

    Declaration
    public static void That<TActual>(ActualValueDelegate<TActual> del, IResolveConstraint expr, NUnitString message = default, string actualExpression = "", string constraintExpression = "")
    Parameters
    Type Name Description
    ActualValueDelegate<TActual> del

    An ActualValueDelegate returning the value to be tested

    IResolveConstraint expr

    A Constraint expression to be applied

    NUnitString message

    The message that will be displayed on failure

    string actualExpression
    string constraintExpression
    Type Parameters
    Name Description
    TActual

    The Type being compared.

    View Source

    That<TActual>(ActualValueDelegate<TActual>, IResolveConstraint, FormattableString, string, string)

    Apply a constraint to a delegate. Returns without throwing an exception when inside a multiple assert block.

    Declaration
    public static void That<TActual>(ActualValueDelegate<TActual> del, IResolveConstraint expr, FormattableString message, string actualExpression = "", string constraintExpression = "")
    Parameters
    Type Name Description
    ActualValueDelegate<TActual> del

    An ActualValueDelegate returning the value to be tested

    IResolveConstraint expr

    A Constraint expression to be applied

    FormattableString message

    The message that will be displayed on failure

    string actualExpression
    string constraintExpression
    Type Parameters
    Name Description
    TActual

    The Type being compared.

    View Source

    That<TActual>(ActualValueDelegate<TActual>, IResolveConstraint, Func<string>, string, string)

    Apply a constraint to a delegate. Returns without throwing an exception when inside a multiple assert block.

    Declaration
    public static void That<TActual>(ActualValueDelegate<TActual> del, IResolveConstraint expr, Func<string> getExceptionMessage, string actualExpression = "", string constraintExpression = "")
    Parameters
    Type Name Description
    ActualValueDelegate<TActual> del

    An ActualValueDelegate returning the value to be tested

    IResolveConstraint expr

    A Constraint expression to be applied

    Func<string> getExceptionMessage

    A function to build the message included with the Exception

    string actualExpression
    string constraintExpression
    Type Parameters
    Name Description
    TActual

    The Type being compared.

    View Source

    That<TActual>(TActual, IResolveConstraint, NUnitString, string, string)

    Apply a constraint to an actual value. Returns without throwing an exception when inside a multiple assert block.

    Declaration
    public static void That<TActual>(TActual actual, IResolveConstraint expression, NUnitString message = default, string actualExpression = "", string constraintExpression = "")
    Parameters
    Type Name Description
    TActual actual

    The actual value to test

    IResolveConstraint expression

    A Constraint expression to be applied

    NUnitString message

    The message that will be displayed on failure

    string actualExpression
    string constraintExpression
    Type Parameters
    Name Description
    TActual

    The Type being compared.

    View Source

    That<TActual>(TActual, IResolveConstraint, FormattableString, string, string)

    Apply a constraint to an actual value. Returns without throwing an exception when inside a multiple assert block.

    Declaration
    public static void That<TActual>(TActual actual, IResolveConstraint expression, FormattableString message, string actualExpression = "", string constraintExpression = "")
    Parameters
    Type Name Description
    TActual actual

    The actual value to test

    IResolveConstraint expression

    A Constraint expression to be applied

    FormattableString message

    The message that will be displayed on failure

    string actualExpression
    string constraintExpression
    Type Parameters
    Name Description
    TActual

    The Type being compared.

    View Source

    That<TActual>(TActual, IResolveConstraint, Func<string>, string, string)

    Apply a constraint to an actual value. Returns without throwing an exception when inside a multiple assert block.

    Declaration
    public static void That<TActual>(TActual actual, IResolveConstraint expression, Func<string> getExceptionMessage, string actualExpression = "", string constraintExpression = "")
    Parameters
    Type Name Description
    TActual actual

    The actual value to test

    IResolveConstraint expression

    A Constraint expression to be applied

    Func<string> getExceptionMessage

    A function to build the message included with the Exception

    string actualExpression
    string constraintExpression
    Type Parameters
    Name Description
    TActual

    The Type being compared.

    View Source

    Throws(IResolveConstraint, TestDelegate)

    Verifies that a delegate throws a particular exception when called. The returned exception may be null when inside a multiple assert block.

    Declaration
    public static Exception? Throws(IResolveConstraint expression, TestDelegate code)
    Parameters
    Type Name Description
    IResolveConstraint expression

    A constraint to be satisfied by the exception

    TestDelegate code

    A TestSnippet delegate

    Returns
    Type Description
    Exception
    View Source

    Throws(IResolveConstraint, TestDelegate, string, params object?[]?)

    Verifies that a delegate throws a particular exception when called. The returned exception may be null when inside a multiple assert block.

    Declaration
    public static Exception? Throws(IResolveConstraint expression, TestDelegate code, string message, params object?[]? args)
    Parameters
    Type Name Description
    IResolveConstraint expression

    A constraint to be satisfied by the exception

    TestDelegate code

    A TestSnippet delegate

    string message

    The message that will be displayed on failure

    object[] args

    Arguments to be used in formatting the message

    Returns
    Type Description
    Exception
    View Source

    Throws(Type, TestDelegate)

    Verifies that a delegate throws a particular exception when called. The returned exception may be null when inside a multiple assert block.

    Declaration
    public static Exception? Throws(Type expectedExceptionType, TestDelegate code)
    Parameters
    Type Name Description
    Type expectedExceptionType

    The exception Type expected

    TestDelegate code

    A TestDelegate

    Returns
    Type Description
    Exception
    View Source

    Throws(Type, TestDelegate, string, params object?[]?)

    Verifies that a delegate throws a particular exception when called. The returned exception may be null when inside a multiple assert block.

    Declaration
    public static Exception? Throws(Type expectedExceptionType, TestDelegate code, string message, params object?[]? args)
    Parameters
    Type Name Description
    Type expectedExceptionType

    The exception Type expected

    TestDelegate code

    A TestDelegate

    string message

    The message that will be displayed on failure

    object[] args

    Arguments to be used in formatting the message

    Returns
    Type Description
    Exception
    View Source

    ThrowsAsync(IResolveConstraint, AsyncTestDelegate)

    Verifies that an async delegate throws a particular exception when called. The returned exception may be null when inside a multiple assert block.

    Declaration
    public static Exception? ThrowsAsync(IResolveConstraint expression, AsyncTestDelegate code)
    Parameters
    Type Name Description
    IResolveConstraint expression

    A constraint to be satisfied by the exception

    AsyncTestDelegate code

    A TestSnippet delegate

    Returns
    Type Description
    Exception
    View Source

    ThrowsAsync(IResolveConstraint, AsyncTestDelegate, string, params object?[]?)

    Verifies that an async delegate throws a particular exception when called. The returned exception may be null when inside a multiple assert block.

    Declaration
    public static Exception? ThrowsAsync(IResolveConstraint expression, AsyncTestDelegate code, string message, params object?[]? args)
    Parameters
    Type Name Description
    IResolveConstraint expression

    A constraint to be satisfied by the exception

    AsyncTestDelegate code

    A TestSnippet delegate

    string message

    The message that will be displayed on failure

    object[] args

    Arguments to be used in formatting the message

    Returns
    Type Description
    Exception
    View Source

    ThrowsAsync(Type, AsyncTestDelegate)

    Verifies that an async delegate throws a particular exception when called. The returned exception may be null when inside a multiple assert block.

    Declaration
    public static Exception? ThrowsAsync(Type expectedExceptionType, AsyncTestDelegate code)
    Parameters
    Type Name Description
    Type expectedExceptionType

    The exception Type expected

    AsyncTestDelegate code

    A TestDelegate

    Returns
    Type Description
    Exception
    View Source

    ThrowsAsync(Type, AsyncTestDelegate, string, params object?[]?)

    Verifies that an async delegate throws a particular exception when called. The returned exception may be null when inside a multiple assert block.

    Declaration
    public static Exception? ThrowsAsync(Type expectedExceptionType, AsyncTestDelegate code, string message, params object?[]? args)
    Parameters
    Type Name Description
    Type expectedExceptionType

    The exception Type expected

    AsyncTestDelegate code

    A TestDelegate

    string message

    The message that will be displayed on failure

    object[] args

    Arguments to be used in formatting the message

    Returns
    Type Description
    Exception
    View Source

    ThrowsAsync<TActual>(AsyncTestDelegate)

    Verifies that an async delegate throws a particular exception when called. The returned exception may be null when inside a multiple assert block.

    Declaration
    public static TActual? ThrowsAsync<TActual>(AsyncTestDelegate code) where TActual : Exception
    Parameters
    Type Name Description
    AsyncTestDelegate code

    A TestDelegate

    Returns
    Type Description
    TActual
    Type Parameters
    Name Description
    TActual

    Type of the expected exception

    View Source

    ThrowsAsync<TActual>(AsyncTestDelegate, string, params object?[]?)

    Verifies that an async delegate throws a particular exception when called. The returned exception may be null when inside a multiple assert block.

    Declaration
    public static TActual? ThrowsAsync<TActual>(AsyncTestDelegate code, string message, params object?[]? args) where TActual : Exception
    Parameters
    Type Name Description
    AsyncTestDelegate code

    A TestDelegate

    string message

    The message that will be displayed on failure

    object[] args

    Arguments to be used in formatting the message

    Returns
    Type Description
    TActual
    Type Parameters
    Name Description
    TActual

    Type of the expected exception

    View Source

    Throws<TActual>(TestDelegate)

    Verifies that a delegate throws a particular exception when called. The returned exception may be null when inside a multiple assert block.

    Declaration
    public static TActual? Throws<TActual>(TestDelegate code) where TActual : Exception
    Parameters
    Type Name Description
    TestDelegate code

    A TestDelegate

    Returns
    Type Description
    TActual
    Type Parameters
    Name Description
    TActual

    Type of the expected exception

    View Source

    Throws<TActual>(TestDelegate, string, params object?[]?)

    Verifies that a delegate throws a particular exception when called. The returned exception may be null when inside a multiple assert block.

    Declaration
    public static TActual? Throws<TActual>(TestDelegate code, string message, params object?[]? args) where TActual : Exception
    Parameters
    Type Name Description
    TestDelegate code

    A TestDelegate

    string message

    The message that will be displayed on failure

    object[] args

    Arguments to be used in formatting the message

    Returns
    Type Description
    TActual
    Type Parameters
    Name Description
    TActual

    Type of the expected exception

    View Source

    Warn(string)

    Issues a warning using the message and arguments provided.

    Declaration
    public static void Warn(string message)
    Parameters
    Type Name Description
    string message

    The message to display.

    • View Source
    In this article
    Back to top Generated by DocFX | Copyright (c) 2018- The NUnit Project - Licensed under CC BY-NC-SA 4.0