2012-02-20 7 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

答えて

2

テストを見ることなく、重要なステップ(Given)が不足しているようです。通常は次のようになります。

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(Given、When、Then)です。それはGherkinの言語なので、Googleの場合は、より多くの情報が表示されます。特定のステップで複数のものがある場合は、And、例:When ...... And.......When...... When........

+1

これに追加するには、Then条件以外のassertを実行する必要があるようではありません。 Givensはセットアップ(ブラウザでは何もしない可能性があります)、ユーザーの操作が必要な場合はアサートを行います。少なくとも私たちはこれを成功させてきました。 – Andy

+0

これは真実ですが、ガーキンのキーワードは必須ではなく、TECHNICALという観点からは重要ではありません。意味と読みやすさの観点から私は完全に同意します –