如何在运行时获取Visual Studio测试框架中的测试用例名称?

发布于 2024-09-24 04:32:17 字数 422 浏览 0 评论 0原文

如何在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

愁杀 2024-10-01 04:32:17

该文档不是 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?

欢烬 2024-10-01 04:32:17

这很简单 this.TestContext.TestName 给出测试用例名称

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文