[TestInitialize]
public void SetUp()
{
//Do required actions before every test
}
[TestMethod]
public void Test1()
{
//Actual test
Assert.AreEqual(1, 0);
}
[TestCleanup]
public void TearDown()
{
//If TestMethod has failed - Get the exeception thrown by the TestMethod. So based on this I can take some action?
}
I am able to get TestMethod Name, Test outcome from TestContext. However I want to get the stacktrace of TestMethod in TestCleanup.
Secondly I know one way of achiving this is by wraping test method steps in a try / catch block and setting the exception to a variable or a property and acessing it in tear down.
However I do not want to wrap each and every testmethod in try/catch block. Is there any other cleaner approach available?
I would appriciate a little detailed explaination or an example as I am a novice in MSTest and programming.