找出下一个测试方法MS TestInitialize执行 [英] Find out the next test method to execute in MS TestInitialize

查看:321
本文介绍了找出下一个测试方法MS TestInitialize执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我把测试数据文件夹的具体测试方法命名一样的功能。我以前曾在每个 [TestMethod的] ClearAllAndLoadTestMethodData()它通过确定的方法名称<$相同的函数调用C $ C>堆栈跟踪。现在,我搬到这个功能 [TestInitialize] 。我怎样才能找到即将要执行的方法的名称?

I keep the test data for specific test method in folder named the same as function. I previously had the same function call in each [TestMethod], ClearAllAndLoadTestMethodData() which determined the method name via StackTrace. Now, I moved this function to [TestInitialize]. How can I find the name of the method that is about to be executed?

我觉得的TestContext 提供这一点。我通过访问它 [AssemblyInitialize()] 并在第一次运行其财产名称设置为名称测试方法。不过,后来这不会改变(如果我保存静态字段的对象)。

I thought TestContext provide this. I have access to it via [AssemblyInitialize()] and on first run its property Name is set to name of the testmethod. However, later this doesn't change (if I save the object in static field).

推荐答案

AssemblyInitialize 是所有测试之前只执行一次的方法。

The AssemblyInitialize method is executed only once before all your tests.

使用的的TestContext TestInitialize 方法中:

[TestClass]
public class TestClass
{
    [TestInitialize]
    public void TestIntialize()
    {
        string testMethodName = TestContext.TestName;
    }

    [TestMethod]
    public void TestMethod()
    {
    }

    public TestContext TestContext { get; set; }
}

这篇关于找出下一个测试方法MS TestInitialize执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆