0 votes
by (2.5k points)
I am using MSTest and want to get the name of the test being run for both logging and debugging. So basically, when I output logs I want to be able to say "Currently running test XYZ" in my TestInitialize and Cleanup.

1 Answer

0 votes
by (2.5k points)

It's somewhat hidden, but if you create a public property for the type "TestContext" with a get/set like so, MSTest will automatically populate it with a bunch of information about the currently running test. 

[TestClass]
public class UnitTest1
{
	public TestContext TestContext { get; set; }
	
	[TestInitialize]
	public void SetupTest()
	{
		Console.WriteLine(TestContext.TestName);
	}
}

 

 

Welcome to .NET Q&A, where you can ask questions and receive answers from other members of the community.
...