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 ステップは検出されますが、Wh​​en ステップは検出されません。私が得るエラーは次のとおりです。

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 に答える