2014-08-29 127 views
1

我知道,在編碼的UI中,有兩種方法(MyTestInitialize和MyTestCleanup)可以在每次測試之前和之後執行操作。我需要添加一些在所有測試之前和之後啓動的操作。例如,如果您熟悉rspec,則在()和after()之前有兩個方法,它們採用參數:each(將在每次測試之前/之後調用)或:all(將在所有測試之前/之後調用)。我可以在所有測試之前/之後執行操作

回答

2

根據需要使用[ClassInitialize]和[ClassCleanup]屬性創建您的方法。這應該在你的測試類中。例如:

[CodedUITest] 
public class MyTestClass 
{ 
    [ClassInitialize] 
    public void DoSomethingFirst() 
    { 
     // your code here that will run at the beginning of each test run. 
    } 

    [TestInitialize] 
    public void RunBeforeEachTest() 
    { 
     // your test initialization here 
    } 

    [TestMethod] 
    public void MyTestMethod() 
    { 
    } 
} 

而且你會爲[TestCleanup]和[ClassCleanup]做同樣的事情。

有關該屬性的更多信息可查詢here.

相關問題