views:

69

answers:

2

Hi,

I've a test class named MyClass. MyClass has a TestFixtureSetUp that loads some initial data. I want to mark whole class as Inconclusive when loading initial data fails. Just like when somebody marks a test method Inconclusive by calling Assert.Inconclusive().

Is there any solution?

+2  A: 

Try this:

  • In your TestFixtureSetUp, store a static value in the class to indicate whether the data has yet to be loaded, was successfully loaded, or was attempted but unsuccessfully loaded.

  • In your SetUp for each test, check the value.

  • If it indicates an unsuccessful load, immediately bomb out by calling Assert.Inconclusive().

John Feminella
Smart solution, Thanks!
afsharm
+3  A: 

You can work around it using Setup by signaling it when a data loading failed.

For example:

[TestFixture]
public class ClassWithDataLoad
{
    private bool loadFailed;

    [TestFixtureSetUp]
    public void FixtureSetup()
    {
        // Assuming loading failure throws exception.
        // If not if-else can be used.
        try 
        {
            // Try load data
        }
        catch (Exception)
        {
            loadFailed = true;
        }
    }

    [SetUp]
    public void Setup()
    {
        if (loadFailed)
        {
            Assert.Inconclusive();
        }
    }

    [Test] public void Test1() { }        
    [Test] public void Test2() { }
}

Nunit does not support Assert.Inconclusive() in the TestFixtureSetUp. If a call to Assert.Inconclusive() is done there all the tests in the fixture appear as failed.

Elisha
Thanks for your solution Elisha. It works as well as John's.
afsharm