SpecFlow错误:尚未实现一个或多个步骤定义

时间:2018-02-16 13:35:06

标签: c# specflow

我创建了一个新的SpecFlow特征文件,我通过右键单击然后生成步骤定义来创建步骤定义..."

步骤定义文件SpecFlowFeature1Steps.cs就在那里,并且特征文件的intellisense没有标记紫色的任何行(这是为了缺少步骤定义)。

然而,当我进行单元测试时,我得到了:

One or more step definitions are not implemented yet.
  SpecFlowFeature1Steps.GivenIHaveEnteredIntoTheCalculator(50)Given I have entered 50 into the calculator
-> pending: SpecFlowFeature1Steps.GivenIHaveEnteredIntoTheCalculator(50)
And I have entered 70 into the calculator
-> skipped because of previous errors
When I press add
-> skipped because of previous errors
Then the result should be 120 on the screen
-> skipped because of previous errors

这是功能文件:

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 add
    Then the result should be 120 on the screen

这是步骤定义文件:

using System;
using TechTalk.SpecFlow;

namespace UnitTestProject1
{
    [Binding]
    public class SpecFlowFeature1Steps
    {
        [Given(@"I have entered (.*) into the calculator")]
        public void GivenIHaveEnteredIntoTheCalculator(int p0)
        {
            ScenarioContext.Current.Pending();
        }

        [When(@"I press add")]
        public void WhenIPressAdd()
        {
            ScenarioContext.Current.Pending();
        }

        [Then(@"the result should be (.*) on the screen")]
        public void ThenTheResultShouldBeOnTheScreen(int p0)
        {
            ScenarioContext.Current.Pending();
        }
    }
}

1 个答案:

答案 0 :(得分:5)

我必须从所有方法中删除ScenarioContext.Current.Pending();

    [Given(@"I have entered (.*) into the calculator")]
    public void GivenIHaveEnteredIntoTheCalculator(int p0)
    {
        ScenarioContext.Current.Pending(); // remove this
    }

我没有意识到它导致错误,我认为这是因为缺少步骤定义。

无论如何,留下这个以防万一将来遇到同样的错误。