我创建了一个新的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
Run Code Online (Sandbox Code Playgroud)
这是功能文件:
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
Run Code Online (Sandbox Code Playgroud)
这是步骤定义文件:
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();
}
}
}
Run Code Online (Sandbox Code Playgroud)
我不得不ScenarioContext.Current.Pending();从所有方法中删除:
[Given(@"I have entered (.*) into the calculator")]
public void GivenIHaveEnteredIntoTheCalculator(int p0)
{
ScenarioContext.Current.Pending(); // remove this
}
Run Code Online (Sandbox Code Playgroud)
我没有意识到它导致错误,我认为这是因为缺少步骤定义.
无论如何,留下这个以防万一将来遇到同样的错误.
| 归档时间: |
|
| 查看次数: |
794 次 |
| 最近记录: |