2016-05-16 60 views
0

我可以在代碼UI中的一個.cs文件中添加多個測試方法嗎?我可以在編碼UI中以.cs添加多個測試方法嗎

以下是我的代碼。我有兩個功能。 1.登錄並註銷。

我創建了一個CodedUITest1.cs文件,我試圖添加多個方法。難道真的有可能做到這一點

公共類CodedUITest1 { 公共CodedUITest1(){ }

[TestMethod] 
    public void Login() 
    { 
     this.UIMap.Login(); 
     this.UIMap.Assert_Login(); 
     this.UIMap.LogOff(); 
    } 

    [TestMethod] 
    public void LogOff() 
    { 
     this.UIMap.LogOff(); 
    } 

回答

0

是的,你可以在一個測試類的多個測試。你注意到了什麼問題?

通常,我使用TestInitialize屬性來設置共同步驟所有測試,然後將每個測試方法做了不同從該點,並且執行斷言等

public class LoginPageTests 
{ 
    BrowserWindow bw; 
    [TestInitialize] 
    public void GivenLoginPage() 
    { 
     bw = BrowserWindow.Launch("http://yoursite.com/loginPage"); 
    } 

    [TestMethod] 
    public void WhenSupplyingValidCredentials_ThenLoginSucceedsAndAccountsPageIsShown() 
    { 
     Assert.IsTrue(bw.Titles.Any(x => "Login")); 
     HtmlEdit userNameEdit = new HtmlEdit(bw); 
     userNameEdit.SearchProperties.Add("id", "userName"); 
     userNameEdit.Text = "MyUserName"; 

     HtmlEdit passEdit = new HtmlEdit(bw); 
     passEdit.SearchProperties.Add("id", "pass"); 
     passEdit.Text = "MyPassword"; 

     HtmlButton loginButton = new HtmlButton(bw); 
     Mouse.Click(loginButton); 

     // probably can one of the WaitFor* methods to wait for the page to load 
     Assert.IsTrue(bw.Titles.Any(x => "Accounts")); 
    } 

    [TestMethod] 
    public void WhenNoPassword_ThenButtonIsDisabled() 
    { 
     HtmlEdit userNameEdit = new HtmlEdit(bw); 
     userNameEdit.SearchProperties.Add("id", "userName"); 
     userNameEdit.Text = "MyUserName"; 

     HtmlButton loginButton = new HtmlButton(bw); 
     Assert.IsFalse(loginButton.Enabled); 
    } 
} 
相關問題