2013-01-07 74 views
1

我正在使用VS2010,SpecFlow 1.9.0,NUnit 2.6.2和ReSharper 7.1。我从例子中采取一个特征文件:Specflow忽略在F#步骤汇编中的步骤

Feature: SpecFlowFeature1 
    In order to avoid silly mistakes 
    As a math idiot 
    I want to be told the sum of two numbers 

@mytag 
Scenario: Add two numbers 
    Given I have entered 50 into the calculator 
    And I have entered 70 into the calculator 
    When I press the add button 
    Then the result should be 120 on the screen 

我已经在一个单独的F#组装实施步骤定义:

[<TechTalk.SpecFlow.Binding>] 
module StepDefinitions 

open TechTalk.SpecFlow 
open NUnit.Framework 

let [<Given>] ``I have entered (.*) into the calculator`` (a: int) = 
    ScenarioContext.Current.Pending() 

let [<When>] ``I press the add button`` = 
    ScenarioContext.Current.Pending() 

let [<Then>] ``the result should be (.*) on the screen`` (r: int) = 
    ScenarioContext.Current.Pending() 

我已经告诉SpecFlow其中通过在应用程序的stepAssemblies标签找到他们.config

但是,当我运行测试时,它会找到Given和Then步骤,但不会找到When步骤。我得到的错误是:

No matching step definition found for one or more steps. 
using System; 
using TechTalk.SpecFlow; 

namespace MyNamespace 
{ 
    [Binding] 
    public class StepDefinitions 
    { 
     [When(@"I press the add button")] 
     public void WhenIPressTheAddButton() 
     { 
      ScenarioContext.Current.Pending(); 
     } 
    } 
} 

Given I have entered 50 into the calculator 
-> pending: StepDefinitions.I have entered (.*) into the calculator(50) 
And I have entered 70 into the calculator 
-> skipped because of previous errors 
When I press the add button 
-> No matching step definition found for the step. Use the following code to create one: 
     [When(@"I press the add button")] 
     public void WhenIPressTheAddButton() 
     { 
      ScenarioContext.Current.Pending(); 
     } 

Then the result should be 120 on the screen 
-> skipped because of previous errors 

我在哪里出错了,或者是否有F#支持的错误?

+2

相当于给定的C#实际上是'让[]''我按加button''()= ScenarioContext.Current.Pending()' - 请注意多'()''后button' –

+0

卫生署!我一直在盯着那个年代。对不起,这个愚蠢的问题:(如果你将你的评论移到答案,我可以给你奖励点数! – Akash

回答

5

的C#的正确翻译实际上是

let [<When>] ``I press the add button``() = 
    ScenarioContext.Current.Pending() 

注意额外()。由于在原始版本中缺少该功能,该功能具有不同的签名,这意味着它未找到。