In MSTest how to check if last test passed (in TestCleanup) In MSTest how to check if last test passed (in TestCleanup) selenium selenium

In MSTest how to check if last test passed (in TestCleanup)


Solution

if (TestContext.CurrentTestOutcome != UnitTestOutcome.Passed){    // some code}


The answer by @MartinMussmann is correct, but incomplete. To access the "TestContext" object you need to make sure to declare it as a property in your TestClass:

[TestClass]public class BaseTest{    public TestContext TestContext { get; set; }    [TestCleanup]    public void TestCleanup()    {        if (TestContext.CurrentTestOutcome != UnitTestOutcome.Passed)        {            // some code        }    }}

This is also mentioned in the following post.