2

I have a TestClass. In my TestCleanUp function, I want to do conditional actions depending on wether the test had failed.

I could of course wrap each test with try-catch and add a flag which I can later query, but I was wondering if there is something built-in to the testing framework.

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
Mugen
  • 8,301
  • 10
  • 62
  • 140

1 Answers1

2

The TestContext.CurrentTestOutcome property contains this information. You can gain access to the current TestContext instance by adding a TestContext property to your test class. e.g.:

[TestClass]
public class YourTestClass
{
    public TestContext TestContext { get; set; }

    //...
}
Nicole Calinoiu
  • 20,843
  • 2
  • 44
  • 49