문제

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);
    }
}
도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top