开发者

How to obtain test case name in Visual Studio Test Framework at runtime?

开发者 https://www.devze.com 2023-01-16 17:59 出处:网络
How can i get test case name during runtime in Visual Studio Test Framework? I am using VS 2010 to write my unit test cases and I need to get test case name during Test Init for each test and save th

How can i get test case name during runtime in Visual Studio Test Framework?

I am using VS 2010 to write my unit test cases and I need to get test case name during Test Init for each test and save those in file.

Sample Code

[TestInitialize()]
public void MyTestInitialize() 
{
    string testCaseName = //Find way to get test case name of this test case
    //Sav开发者_如何学Pythone Logic with TestCaseName

}

[TestMethod]
public void T_1()
{
  //Execute Test
}

[TestMethod]
public void T_2()
{
  //Execute Test
}


The documentation is not 100% clear, but does the TestName property of the TestContext instance for your class give you what you need?


It is simple enough this.TestContext.TestName gives test case Name

0

精彩评论

暂无评论...
验证码 换一张
取 消