I need to capture Unit test case result and pass it into an array. How can I do that?

北战南征 提交于 2020-05-30 07:03:26

问题


I need to capture Unit test case result that is pass/fail in form of 1 and 2 and save it into an array for multiple test cases results. 1 for pass and 2 for fail. What if i need to save only one test case result? How can I do that? I am using Nunit C#. Using selenium webdriver. Here is the glimpse of my code

[Priority(1)]
    [TestMethod]
    public void search()
    {
        Testlog.Info("Test ID:001);

        Testlog.Info("Select customer from cutomer dropdown");
        var dc = gmethods.GetSelectElement(WDriver, dpo.customermenu);
        dc.SelectByText(dpc.customer);
    }
}

回答1:


In principal this is the same question you asked here

This is the answer I gave for that, perhaps you should close this as a duplicate.

For NUnit you can access the result and other details of the test using properties found in TestContext.CurrentContext.

For your problem you can add the following check to the test teardown method

if(TestContext.CurrentContext.Result.Outcome.Status == TestStatus.Passed) { .... }

For MSTest add the following property to your test class

public TestContext TestContext { get; set; } 

Then use it by adding the following to TestCleanup

if(TestContext.CurrentTestOutcome == UnitTestOutcome.Passed) { .... }


来源:https://stackoverflow.com/questions/60826063/i-need-to-capture-unit-test-case-result-and-pass-it-into-an-array-how-can-i-do

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!