测试清理的目的是什么?

时间:2015-02-02 11:10:50

标签: coded-ui-tests

有谁能详细告诉我什么是测试清理为什么我们使用它? 我们为什么在初始化后使用 实际上它做了什么

请详细告诉我

1 个答案:

答案 0 :(得分:2)

测试清理是每次测试后运行的代码。

测试清理是在声明测试的同一个类中声明的。您在TestCleanup中使用的任何断言都可能无法通过测试。如果您在同一位置检查每个可能导致测试失败的测试,则此功能非常有用。

[TestCleanup]
      public void CleanUp()
      {
         AppManager.CheckForHandledExceptions();
      }

以下是需要考虑的重要事件:

[ClassInitialize]
      public static void Init(TestContext testContext)
      {
         //Runs before any test is run in the class - imo not that useful. 
      }

[TestInitialize]
      public void Init()
      {
         //Runs just prior to running a test very useful. 
      }

大多数情况下,我使用TestInitialize重置测试之间的uimap,否则控件引用可能会过时。

接下来,在程序集中的所有测试都运行后,最终会运行(非常适合检查未处理的异常或关闭应用程序)。

因此,如果你通过MTM运行100次测试,在完成最后一次测试之后,AssemblyCleaup将会运行,同时注意这个方法有点特殊,它在每个程序集中声明一次,在它自己的类中具有[CodedUITest]属性类。

[CodedUITest]
   public class TestRunCleanup
   {
      [AssemblyCleanup()]
      public static void AssemblyCleanup()
      {
         AppManager.CloseApplicationUnderTest();
      }
   }
相关问题