2012-02-20 44 views
1

我正在嘗試使用Specflow,NUnit和WatiN進行一些BDD測試。我正在使用TestDriven.NEt來運行測試。這是我的第一個測試:NUnit,TestDriven.NET,WatiN和Specflow

[Binding] 
    [TestFixture, RequiresSTA] 
    public class RegisterUserSteps 
    { 
     private IE _ie = new IE(); 

     [When(@"the user visits the registration page")] 
     public void WhenTheUserVisitsTheRegistrationPage() 
     { 
      _ie.GoTo("http://localhost:1064/Register/"); 
     } 


     [When(@"enter the following information")] 
     public void WhenEnterTheFollowingInformation(Table table) 
     { 
      foreach(var tableRow in table.Rows) 
      { 
       var field = _ie.TextField(Find.ByName(tableRow["Field"])); 

       if(!field.Exists) 
       { 
        Assert.Fail("Field does not exists!"); 
       } 

       field.TypeText(tableRow["Value"]); 
      } 
     } 

     [When(@"click the ""Register"" button")] 
     public void WhenClickTheRegisterButton() 
     { 
      ScenarioContext.Current.Pending(); 
     } 

     [Then(@"the user should be registered")] 
     public void ThenTheUserShouldBeRegistered() 
     { 
      ScenarioContext.Current.Pending(); 
     } 

    } 

的問題是,它從未進入到

[When(@"enter the following information")] 
      public void WhenEnterTheFollowingInformation(Table table) 

它只是啓動瀏覽器並執行的第一步。我錯過了什麼嗎?

+0

你能後的實際特徵的文字? – Andy 2012-02-20 03:11:48

回答

2

不看這個測試,看起來你錯過了一個重要的步驟(鑑於)。通常是這樣的:

Given I go to some page 
And all the set up data are available - optional 
When I enter the following info 
And I click "Register" button 
Then I see something 

基本上這些步驟是GWT(給定,當,然後)。這是黃瓜語言,所以如果你谷歌它,你會看到更多的信息。當你有多個事情給定步,你必須使用And,例如,When ...... And.......,不When...... When........

+1

爲了補充說明,除了在Then條件下,似乎並不像你應該做的那樣。吉文斯做了一些事情來設置(在瀏覽器中可能不會做任何事情),何時應該是用戶操作,以及斷言。至少我們已經取得了很大的成功。 – Andy 2012-02-20 03:11:31

+0

這是真的,但重要的是要注意的是,從技術的角度來看,所有的關鍵字都不是必需的,它們的順序也不重要。但從語義和可讀性的角度來看,我完全同意 – 2012-02-20 19:22:59

相關問題