<PackageReference Include="NUnit" Version="4.2.2" />

Assert

public abstract class Assert : AssertBase
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.

public static Exception Catch(TestDelegate code, string message, object[] args)

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(TestDelegate code)

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.

public static Exception Catch(Type expectedExceptionType, TestDelegate code)

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.

public static TActual Catch<TActual>(TestDelegate code) 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.

public static Exception CatchAsync(AsyncTestDelegate code, string message, object[] args)

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.

public static Exception CatchAsync(Type expectedExceptionType, AsyncTestDelegate code)

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.

public static TActual CatchAsync<TActual>(AsyncTestDelegate code) 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.

public static void 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.

public static void DoesNotThrow(TestDelegate code, string message, object[] args)

Verifies that a delegate does not throw an exception

public static void DoesNotThrow(TestDelegate code)

Verifies that a delegate does not throw an exception.

public static void DoesNotThrowAsync(AsyncTestDelegate code, string message, object[] args)

Verifies that an async delegate does not throw an exception

public static void DoesNotThrowAsync(AsyncTestDelegate code)

Verifies that an async delegate does not throw an exception.

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.

public static bool Equals(object a, object b)

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.

public static void Fail(string message)

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.

public static void Fail()

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

public static void Ignore(string message)

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

public static void Ignore()

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

public static void Inconclusive(string message)

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

public static void Inconclusive()

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

public static void Multiple(TestDelegate 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.

public static void Multiple(AsyncTestDelegate 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.

public static Task MultipleAsync(AsyncTestDelegate 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.

public static void Pass(string message)

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.

public static void 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.

public static void ReferenceEquals(object a, object b)

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.

public static void That(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(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.

public static Exception Throws(IResolveConstraint expression, TestDelegate code)

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.

public static Exception Throws(Type expectedExceptionType, TestDelegate code)

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.

public static TActual Throws<TActual>(TestDelegate code) 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.

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.

public static Exception ThrowsAsync(Type expectedExceptionType, AsyncTestDelegate code)

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.

public static TActual ThrowsAsync<TActual>(AsyncTestDelegate code) 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.

public static void Warn(string message)

Issues a warning using the message and arguments provided.