问题
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