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