I'm using MSTest and I want to write log entry before test executes and after it finishes. Obviously I don't want to add custom logging code at the beginning and end of each test - it would only make the test unreadable and seemed like a lot of effort (I have > 500 tests)
Using TestInitialize and TestCleanup seemed like the way to go but I can't get the test name.
Does anyone knows how to do this?
In MSTest, the name of the test case is available in the test context property. So to access it in the test initialize (as well as test cleanup) method, you can use something like this: -
[TestInitialize()]
public void MyTestInitialize()
{
if (string.Equals(**TestContext.TestName**, "TestMethod1", StringComparison.OrdinalIgnoreCase))
{
}
}