多个TestInitialize和TestCleanup [英] Multiple TestInitialize and TestCleanup

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

问题描述

是否有一种方法可以为每个测试用例提供特定的初始化和清理方法。问题是每个测试用例都有不同的清理工作。

Is there a way that we can have particular initialize and cleanup methods for each test case. The issue is that there are different cleanups for each test case.

请提供最佳实践建议。

推荐答案

mn1987,

mn1987,

在测试类中为清理方法创建布尔变量,并使用它来驱动初始化/清理方法中的相应操作。

Create boolean variables in your test class for the cleanup methods and use it to drive the appropriate action(s) in your initialize/cleanup methods.


  [CodedUITest]
  public class CodedUITest1
  {
    static bool executeCleanup1 = true;
    static bool executeCleanup2 = false;

    public CodedUITest1()
    {

    }

   

    [TestMethod]
    public void CodedUITestMethod1()
    {
      executeCleanup1 = false;
      executeCleanup2 = true;

      this.UIMap.RecordedMethod1();
      
    }

    public void CodedUITestMethod2()
    {
      executeCleanup1 = false;
      executeCleanup2 = true;

      this.UIMap.RecordedMethod2();
      
    }

    #region Additional test attributes

    [TestCleanup()]
    public void MyTestCleanup()
    {
      if (executeCleanup1)
      {
        //executeCleanup1
      }
      if (executeCleanup2)
      {
        //executeCleanup2
      }
    }

    #endregion


这篇关于多个TestInitialize和TestCleanup的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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