【发布时间】:2019-06-22 12:53:39
【问题描述】:
按照我在网上找到的一些指导,我尝试使用 Specflow 设置 JetBrains Rider:
- generating-specflow-files-in-rider
- using-specflow-3-0-with-rider
- specflow-steps-generation-and-general-rider-changes
...感谢肯提供的文档。
但是,我无法让我的方案步骤链接到我的任何步骤文件。
设置
我相信我已经为最新版本的 SpecFlow 安装了所有必需的 NuGet 包
NuGet installed Specflow packages screenshot
我习惯了 Cucumber 和 IntelliJ,我们也让 SpecFlow C# Visual Studio 工作,但我无法让场景连接到 Rider 中的步骤。
NB - 我尝试在 Rider 中使用的项目正在使用 Specflow 在 Visual Studio 中工作。
还有其他人能够赢得这场战斗吗?
我很想听听如何。
谢谢
更新 @肯 感谢您的建议。
我尝试了以下两种方法:
- 在 .csproj 文件中为 feature.cs 手动添加了 include 操作,但在构建后仍然无法从功能中执行步骤。
- 包含一个 Scope(Feature="") 属性
但不幸的是,没有运气。
- Screenshot - feature and connected steps - Visual Studio
- Screenshot - feature and connected steps - Rider (including .csproj)
如果这不能解决您的问题,您能否发布您的 .feature 和 .steps.cs 文件的内容。
按照建议,以下是在 VS 中正确映射的功能和 step.cs 文件的内容:
.feature
Feature: sampleFeature
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
.steps
using System;
using TechTalk.SpecFlow;
namespace SpecFlowPoc.features.sample
{
[Binding, Scope(Feature="sampleFeature")]
public class SampleFeatureSteps
{
[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();
}
}
}
谢谢
更新 - 已解决
好的,首先,感谢Ken 的帮助和指导。 按照 Ken 提供的步骤,创建一个新项目并抛出异常后,我可以确认 .feature 到 step.cs 绑定有效。
Ken,你是一位绅士和天才。谢谢。
其次,我错误地认为 Rider 会为我提供一种从 .feature 导航到 Steps.cs 代码(Cucumber JVM 风格)的方法。我现在了解到 Rider 尚不支持此功能。
- 这就是为什么我认为绑定不起作用!呵呵。
如果有人找到将 Rider gherkin 映射到小黄瓜库的插件,我很想听听。
【问题讨论】:
-
这很奇怪。我创建了一个 Sample.feature 文件,复制到您的内容中,构建后它向我展示了测试,我可以运行它并生成生成的步骤。然后我添加了一个步骤文件,复制到生成的内容中并将第一个
ScenarioContext.Current.Pending();替换为throw new Exception("this is my exception");。当我运行时,它很好地抛出了异常。您的 SpecFlow 版本和 Rider 版本是什么?我使用 SpecFlow 3.0.220 和 Rider 2019.1.2。 -
嗨,Ken,我认为我的 keyBoard 和 myChair(我)之间存在错误。在遵循您出色的说明和解释之后,我现在明白 Binding 可以工作,测试运行,并且没有 UI 方法可以从 .feature 到 steps。这很酷。太感谢了。你是个传奇。