Incorrect TestOutcome status in Teardown when created from StaticTestFactory

132 views Asked by At

Using MbUnit, I create tests using several StaticTestFactory methods, each having corresponding test setup and teardown methods. A requirement is to log test results to an external system, especially failed ones.

However, I am unable to get the correct test outcome status using TestContext.CurrentContext.Outcome.Status. Using below code, you will see that the test fails, but the Outcome.status is always returned as 'Passed' from FactoryAssignedTearDownMethod, even when both Gallio Icarus and Echo show the test as failed.

Looking for any workaround or fix to get the correct outcome in this scenario.

public class FactoryTest
{
    [StaticTestFactory]
    public static IEnumerable<Test> CreateStaticTests()
    {
        var testcase = new TestCase("simpletest" , () =>
        {
            Assert.Fail("staticfactory created test failed.");
        });

        testcase.TearDown = FactoryAssignedTearDownMethod;

        yield return testcase;
    }

    public static void FactoryAssignedTearDownMethod()
    {
        //outcome value is always 'Passed', even when test fails
        TestLog.WriteLine("Test Outcome Status from factory assigned method: " + TestContext.CurrentContext.Outcome.Status);
    }
}
1

There are 1 answers

0
Faiz On BEST ANSWER

I worked around this by writing a Gallio TestRunnerExtension. By handling the TestStepFinished event, I can get the proper test result for all tests created with the StaticTestFactory.