0

When generating Tests with a StaticTestFactory in mbunit, the test suite needs to run only if a previous test passes. In the below code sample, The test Factory_ShouldNotRun_Test is executed even when the test it depends on fails.

The DependsOn atrtibute works with simple tests but not with a StaticTestFactory.

Any ideas? Thanks in advance.

public class Dependency_Test
{
    [Test]
    public  void DependsOnMe_Test()
    {
        Assert.Fail("I fail and dependent tests should be skipped");
    }

    [Test]
    [DependsOn("DependsOnMe_Test")]
    public  void Simple_Test_ShouldNotRun()
    {
        Assert.Fail("Simple test should not run");
    }

    [StaticTestFactory]
    [DependsOn("DependsOnMe_Test")]
    public static IEnumerable<Test> Factory_ShouldNotRun_Test()
    {

        var testCase = new TestCase("Factory_ShouldNotRun_Test", () =>
        {
            Assert.Fail("Factory test should not run");
        });

        yield return testCase;
    }
}
Faiz
  • 3,216
  • 1
  • 19
  • 25
  • You could just use an instance variable to indicate failure. – Mauricio Scheffer Jun 17 '13 at 05:03
  • Yes I could, though I have several factory methods so each will require its own instance variable, and always ensuring that they are executed in the right order. – Faiz Jun 17 '13 at 07:16

0 Answers0