<PackageReference Include="NUnit" Version="5.0.0-beta.1" />

NUnit.Framework.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(Action 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(Action 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, Action 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, Action 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 TExpected Catch<TExpected>(Action code, string message, object[] args) where TExpected : 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 TExpected Catch<TExpected>(Action code) where TExpected : 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 Task<Exception> CatchAsync(Func<Task> asyncCode, string message, object[] args)

Verifies that an async delegate throws an exception when called and returns it.

public static Task<Exception> CatchAsync(Func<Task> asyncCode)

Verifies that an async delegate throws an exception when called and returns it.

public static Task<Exception> CatchAsync(Type expectedExceptionType, Func<Task> asyncCode, 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.

public static Task<Exception> CatchAsync(Type expectedExceptionType, Func<Task> asyncCode)

Verifies that an async delegate throws an exception of a certain Type or one derived from it when called and returns it.

public static Task<TActual> CatchAsync<TActual>(Func<Task> asyncCode, 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.

public static Task<TActual> CatchAsync<TActual>(Func<Task> asyncCode) 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.

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(Action code, string message, object[] args)

Verifies that a delegate does not throw an exception

public static void DoesNotThrow(Action code)

Verifies that a delegate does not throw an exception.

public static Task DoesNotThrowAsync(Func<Task> asyncCode, string message, object[] args)

Verifies that an async delegate does not throw an exception.

public static Task DoesNotThrowAsync(Func<Task> asyncCode)

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(Action action)

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(Func<Task> asyncAction)

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(Func<Task> asyncAction)

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>(Func<TActual> code, 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>(Func<TActual> code, 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>(Func<TActual> code, 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(Action code, IResolveConstraint constraint, NUnitString message = default, string actualExpression = "", string constraintExpression = "")

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

public static void That(Action code, IResolveConstraint constraint, FormattableString message, string actualExpression = "", string constraintExpression = "")

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

public static void That(Action code, IResolveConstraint constraint, Func<string> getExceptionMessage, string actualExpression = "", string constraintExpression = "")

Apply a constraint to an action. 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(Func<Task> asyncCode, IResolveConstraint constraint, NUnitString message = default, string actualExpression = "", string constraintExpression = "")

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

public static Task ThatAsync(Func<Task> asyncCode, IResolveConstraint constraint, FormattableString message, string actualExpression = "", string constraintExpression = "")

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

public static Task ThatAsync<T>(Func<Task<T>> asyncCode, IResolveConstraint constraint, NUnitString message = default, string actualExpression = "", string constraintExpression = "")

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

public static Task ThatAsync<T>(Func<Task<T>> asyncCode, IResolveConstraint constraint, FormattableString message, string actualExpression = "", string constraintExpression = "")

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

public static TExpected Throws<TExpected>(IResolveConstraint expression, Action code, string message, object[] args) where TExpected : 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 Throws(IResolveConstraint expression, Action 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, Action 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, Action 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 TExpected Throws<TExpected>(Action code, string message, object[] args) where TExpected : 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 TExpected Throws<TExpected>(Action code) where TExpected : 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 Task<Exception> ThrowsAsync(IResolveConstraint expression, Func<Task> asyncCode, string message, object[] args)

Verifies that an async delegate throws a particular exception when called.

public static Task<Exception> ThrowsAsync(IResolveConstraint expression, Func<Task> asyncCode)

Verifies that an async delegate throws a particular exception when called.

public static Task<Exception> ThrowsAsync(Type expectedExceptionType, Func<Task> asyncCode, string message, object[] args)

Verifies that an async delegate throws a particular exception when called.

public static Task<Exception> ThrowsAsync(Type expectedExceptionType, Func<Task> asyncCode)

Verifies that an async delegate throws a particular exception when called.

public static Task<TActual> ThrowsAsync<TActual>(Func<Task> asyncCode, string message, object[] args) where TActual : Exception

Verifies that an async delegate throws a particular exception when called.

public static Task<TActual> ThrowsAsync<TActual>(Func<Task> asyncCode) where TActual : Exception

Verifies that an async delegate throws a particular exception when called.

public static void Warn(string message)

Issues a warning using the message and arguments provided.