Legacy Documentation. View NUnit 3 Documentation

Utility Methods

Two utility methods, Fail() and Ignore() are provided in order to allow more direct control of the test process:

Assert.Fail();
Assert.Fail( string message );
Assert.Fail( string message, object[] parms );

Assert.Ignore();
Assert.Ignore( string message );
Assert.Ignore( string message, object[] parms );

The Assert.Fail method provides you with the ability to generate a failure based on tests that are not encapsulated by the other methods. It is also useful in developing your own project-specific assertions.

Here's an example of its use to create a private assertion that tests whether a string contains an expected value.

public void AssertStringContains( string expected, string actual )
{
    AssertStringContains( expected, actual, string.Empty );
}

public void AssertStringContains( string expected, string actual,
    string message )
{
    if ( actual.IndexOf( expected ) < 0 )
        Assert.Fail( message );
}

The Assert.Ignore method provides you with the ability to dynamically cause a test or suite to be ignored at runtime. It may be called in a test, setup or fixture setup method. We recommend that you use this only in isolated cases. The category facility is provided for more extensive inclusion or exclusion of tests or you may elect to simply divide tests run on different occasions into different assemblies.