如何在运行时获取Visual Studio测试框架中的测试用例名称?
如何在 Visual Studio 测试框架运行时获取测试用例名称?
我正在使用 VS 2010 编写单元测试用例,我需要在每个测试的测试初始化期间获取测试用例名称并将其保存在文件中。
示例代码
[TestInitialize()]
public void MyTestInitialize()
{
string testCaseName = //Find way to get test case name of this test case
//Save Logic with TestCaseName
}
[TestMethod]
public void T_1()
{
//Execute Test
}
[TestMethod]
public void T_2()
{
//Execute Test
}
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
//Save Logic with TestCaseName
}
[TestMethod]
public void T_1()
{
//Execute Test
}
[TestMethod]
public void T_2()
{
//Execute Test
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
该文档不是 100% 清晰,但是您的类的 TestContext 实例的 TestName 属性是否满足您的需要?
The documentation is not 100% clear, but does the TestName property of the TestContext instance for your class give you what you need?
这很简单 this.TestContext.TestName 给出测试用例名称
It is simple enough this.TestContext.TestName gives test case Name