In MSTest How to access the TestMethod test in TestCleanup without using the try / catch block in the test method

[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 can get the name TestMethod, the result of the TestContext test. However, I want to get the testmethod stack in TestCleanup.

Secondly, I know that one of the ways to achieve this is to follow the steps of the break test method in the try / catch block and set an exception for the variable or property and abort it when it fails.

However, I do not want to wrap each test method in a try / catch block. Is there any other approach to cleaning?

I would offer a small detailed explanation or example, as I am new to MSTest and programming.

+6
source share

All Articles