Assert
The Assert class contains a collection of static methods that
implement the most common assertions used in NUnit.
protected Assert()
public static void ByVal(object actual, IResolveConstraint expression, string message = "", string actualExpression = "", string constraintExpression = "")
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.
Verifies that a delegate throws an exception when called and returns it. The returned exception may be null when inside a multiple assert block.
Verifies that a delegate throws an exception when called and returns it. The returned exception may be null when inside a multiple assert block.
public static Exception Catch(Type expectedExceptionType, TestDelegate code, string message, object[] args)
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.
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.
public static TActual Catch<TActual>(TestDelegate code, string message, object[] args) where TActual : Exception
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.
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.
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.
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.
public static Exception CatchAsync(Type expectedExceptionType, AsyncTestDelegate code, string message, object[] args)
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.
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.
public static TActual CatchAsync<TActual>(AsyncTestDelegate code, string message, object[] args) where TActual : Exception
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.
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.
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.
Verifies that a delegate does not throw an exception
Verifies that a delegate does not throw an exception.
Verifies that an async delegate does not throw an exception
Verifies that an async delegate does not throw an exception.
DO NOT USE! Use Assert.That(x,Is.EqualTo) instead.
The Equals method throws an InvalidOperationException. This is done
to make sure there is no mistake by calling this function.
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.
Marks the test as failed. Returns without throwing an exception when inside a multiple assert block.
Throws an IgnoreException with the message and arguments
that are passed in. This causes the test to be reported as ignored.
Throws an IgnoreException.
This causes the test to be reported as ignored.
Throws an InconclusiveException with the message and arguments
that are passed in. This causes the test to be reported as inconclusive.
Throws an InconclusiveException.
This causes the test to be reported as Inconclusive.
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.
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.
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.
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.
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.
DO NOT USE!
The ReferenceEquals method throws an InvalidOperationException. This is done
to make sure there is no mistake by calling this function.
public static void That(bool condition, NUnitString message = default, string actualExpression = "")
Asserts that a condition is true. Returns without throwing an exception when inside a multiple assert block.
Asserts that a condition is true. Returns without throwing an exception when inside a multiple assert block.
public static void That(bool condition, Func<string> getExceptionMessage, string actualExpression = "")
Asserts that a condition is true. Returns without throwing an exception when inside a multiple assert block.
public static void That(Func<bool> condition, NUnitString message = default, string actualExpression = "")
Asserts that a condition is true. Returns without throwing an exception when inside a multiple assert block.
public static void That(Func<bool> condition, FormattableString message, string actualExpression = "")
Asserts that a condition is true. Returns without throwing an exception when inside a multiple assert block.
public static void That(Func<bool> condition, Func<string> getExceptionMessage, string actualExpression = "")
Asserts that a condition is true. Returns without throwing an exception when inside a multiple assert block.
public static void That<TActual>(ActualValueDelegate<TActual> del, IResolveConstraint expr, NUnitString message = default, string actualExpression = "", string constraintExpression = "")
Apply a constraint to a delegate. Returns without throwing an exception when inside a multiple assert block.
public static void That<TActual>(ActualValueDelegate<TActual> del, IResolveConstraint expr, FormattableString message, string actualExpression = "", string constraintExpression = "")
Apply a constraint to a delegate. Returns without throwing an exception when inside a multiple assert block.
public static void That<TActual>(ActualValueDelegate<TActual> del, IResolveConstraint expr, Func<string> getExceptionMessage, string actualExpression = "", string constraintExpression = "")
Apply a constraint to a delegate. Returns without throwing an exception when inside a multiple assert block.
public static void That(TestDelegate code, IResolveConstraint constraint, NUnitString message = default, string actualExpression = "", string constraintExpression = "")
Apply a constraint to a delegate. Returns without throwing an exception when inside a multiple assert block.
public static void That(TestDelegate code, IResolveConstraint constraint, FormattableString message, string actualExpression = "", string constraintExpression = "")
Apply a constraint to a delegate. Returns without throwing an exception when inside a multiple assert block.
public static void That(TestDelegate code, IResolveConstraint constraint, Func<string> getExceptionMessage, string actualExpression = "", string constraintExpression = "")
Apply a constraint to a delegate. Returns without throwing an exception when inside a multiple assert block.
public static void That<TActual>(TActual actual, IResolveConstraint expression, NUnitString message = default, string actualExpression = "", string constraintExpression = "")
Apply a constraint to an actual value. Returns without throwing an exception when inside a multiple assert
block.
public static void That<TActual>(TActual actual, IResolveConstraint expression, FormattableString message, string actualExpression = "", string constraintExpression = "")
Apply a constraint to an actual value. Returns without throwing an exception when inside a multiple assert
block.
public static void That<TActual>(TActual actual, IResolveConstraint expression, Func<string> getExceptionMessage, string actualExpression = "", string constraintExpression = "")
Apply a constraint to an actual value. Returns without throwing an exception when inside a multiple assert
block.
public static Task ThatAsync(AsyncTestDelegate code, IResolveConstraint constraint, NUnitString message = default, string actualExpression = "", string constraintExpression = "")
Apply a constraint to an async delegate. Returns without throwing an exception when inside a multiple assert block.
public static Task ThatAsync(AsyncTestDelegate code, IResolveConstraint constraint, FormattableString message, string actualExpression = "", string constraintExpression = "")
Apply a constraint to an async delegate. Returns without throwing an exception when inside a multiple assert block.
public static Task ThatAsync<T>(Func<Task<T>> code, IResolveConstraint constraint, NUnitString message = default, string actualExpression = "", string constraintExpression = "")
Apply a constraint to an async delegate. Returns without throwing an exception when inside a multiple assert block.
public static Task ThatAsync<T>(Func<Task<T>> code, IResolveConstraint constraint, FormattableString message, string actualExpression = "", string constraintExpression = "")
Apply a constraint to an async delegate. Returns without throwing an exception when inside a multiple assert block.
public static Exception Throws(IResolveConstraint expression, TestDelegate code, string message, object[] args)
Verifies that a delegate throws a particular exception when called. The returned exception may be null when inside a multiple assert block.
Verifies that a delegate throws a particular exception when called. The returned exception may be null when inside a multiple assert block.
public static Exception Throws(Type expectedExceptionType, TestDelegate code, string message, object[] args)
Verifies that a delegate throws a particular exception when called. The returned exception may be null when inside a multiple assert block.
Verifies that a delegate throws a particular exception when called. The returned exception may be null when inside a multiple assert block.
public static TActual Throws<TActual>(TestDelegate code, string message, object[] args) where TActual : Exception
Verifies that a delegate throws a particular exception when called. The returned exception may be null when inside a multiple assert block.
Verifies that a delegate throws a particular exception when called. The returned exception may be null when inside a multiple assert block.
public static Exception ThrowsAsync(IResolveConstraint expression, AsyncTestDelegate code, string message, object[] args)
Verifies that an async delegate throws a particular exception when called. The returned exception may be
null when inside a multiple assert block.
Verifies that an async delegate throws a particular exception when called. The returned exception may be
null when inside a multiple assert block.
public static Exception ThrowsAsync(Type expectedExceptionType, AsyncTestDelegate code, string message, object[] args)
Verifies that an async delegate throws a particular exception when called. The returned exception may be
null when inside a multiple assert block.
Verifies that an async delegate throws a particular exception when called. The returned exception may be
null when inside a multiple assert block.
public static TActual ThrowsAsync<TActual>(AsyncTestDelegate code, string message, object[] args) where TActual : Exception
Verifies that an async delegate throws a particular exception when called. The returned exception may be
null when inside a multiple assert block.
Verifies that an async delegate throws a particular exception when called. The returned exception may be
null when inside a multiple assert block.
Issues a warning using the message and arguments provided.