Ignore Test or TestFixture based on a condition

Use some code in your test or fixture set up method that detects if the simulation software is installed or not and calls Assert.Ignore() if it isn’t.

[SetUp]
public void TestSetUp() 
{
     if (!TestHelper.SimulationFilesExist())
     {
         Assert.Ignore( "Simulation files are not installed.  Omitting." );
     }
}

or

[TestFixtureSetUp]
public void FixtureSetUp()
{
     if (!TestHelper.SimulationFilesExist())
     {
         Assert.Ignore( "Simulation files are not installed.  Omitting fixture." );
     }
}

In NUnit 3.0 and higher you have to use OneTimeSetUp attribute instead of TestFixtureSetUp.

Leave a Comment

tech