1

我正在使用 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# 支持存在错误?

4

1 回答 1

5

C#的正确翻译其实是

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

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

于 2013-01-08T10:44:20.263 回答