我使用的是VS2010,SpecFlow 1.9.0,NUnit 2.6.2和ReSharper 7.1。我有一个从示例中获取的功能文件:
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()
我已经通过app.config
中的stepAssemblies标签告诉SpecFlow在哪里找到它们但是,当我运行测试时,它会找到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#支持的错误?
答案 0 :(得分:5)
C#的正确翻译实际上是
let [<When>] ``I press the add button``() =
ScenarioContext.Current.Pending()
请注意额外的()
。由于原始版本中缺少此功能,因此该功能具有不同的签名,这意味着找不到它。