无法将我的功能绑定到使用 Specflow 和 JetBrains Rider 的步骤
Unable to bind my feature to Steps using Specflow with JetBrains Rider
我已尝试使用 Specflow 设置 JetBrains Rider,遵循我在网上找到的一些指南:
- generating-specflow-files-in-rider
- using-specflow-3-0-with-rider
- specflow-steps-generation-and-general-rider-changes
...感谢 Ken 提供的文档。
但是,我无法将 link 的场景步骤添加到我的任何步骤文件中。
设置
我相信我已经为最新版本的 SpecFlow 安装了所有必需的 NuGet 包
NuGet installed Specflow packages screenshot
我习惯了 Cucumber with IntelliJ,我们也有 SpecFlow C# Visual Studio 可以工作,但我就是无法连接到 Rider 中的步骤。
NB - 我试图在 Rider 中使用的项目正在 Visual Studio 中使用 Specflow。
还有其他人能够赢得这场战斗吗?
我很想听听。
谢谢
更新
@肯
感谢您的建议。
我尝试了以下两种方法:
- 在 feature.cs 的 .csproj 文件中手动添加 include 操作,但构建后仍然无法从功能中获取步骤。
- 包含范围(Feature="") 属性
但不幸的是,没有运气。
- Screenshot - feature and connected steps - Visual Studio
- 屏幕截图 - 功能和相关步骤 - Rider(包括
.csproj)
If this does not solve you problem, can you post the content of your .feature and .steps.cs files.
根据建议,下面是功能和 step.cs 文件的内容,它们在 VS 中正确映射。:
.特征
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
.步数
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 映射到 gherkin 库的插件,我很想听听。
我能想到的第一件事(我自己已经做过多次)是忘记 .steps.cs 文件中的 [Binding]
属性.哦,您可能还想标记一个 [Scope(Feature="")]
属性,只是为了避免歧义。
您可以做的另一件事(如果您使用的是 SpecFlow 3.0 及更高版本)是手动包含 .feature.cs 文件,看看是否能解决您的问题。如果是这样,我会考虑检查 .csproj 文件是否正确包含 .feature.cs 文件。
如果这不能解决您的问题,您可以 post 您的 .feature 和 .steps.cs[= 的内容吗? 43=] 个文件。
编辑
我从头开始,这些是我采取的步骤:
- 创建新解决方案
- 创建一个测试项目,select NUnit 作为测试框架
- 安装最新的 SpecFlow.NUnit 和 SpecFlow.Tools.MsBuild.Generation
- nuget 包(应该是版本 3.0.220)(这将自动安装正确的 SpecFlow nuget 包)
- 编辑 .csconfig 并添加
<Target Name="AfterUpdateFeatureFilesInProject">
<!-- include any generated SpecFlow files in the compilation of the project if not included yet -->
<ItemGroup>
<Compile Include="**\*.feature.cs" Exclude="@(Compile)" />
</ItemGroup>
</Target>
- 创建一个 .feature 文件并粘贴堆栈溢出问题中的内容
- 构建项目,这应该会在测试资源管理器中显示您的测试
运行 获得定义的测试
- 创建一个 class 以将定义放入(同样是 Binding 和 Scope 属性),从测试输出中复制这些定义 window
- 在 Given 方法中抛出异常
- 重新运行测试并查看是否抛出异常
PS: 你的秘密身份对我来说是安全的。 ;)
我已尝试使用 Specflow 设置 JetBrains Rider,遵循我在网上找到的一些指南:
- generating-specflow-files-in-rider
- using-specflow-3-0-with-rider
- specflow-steps-generation-and-general-rider-changes
...感谢 Ken 提供的文档。
但是,我无法将 link 的场景步骤添加到我的任何步骤文件中。
设置
我相信我已经为最新版本的 SpecFlow 安装了所有必需的 NuGet 包
NuGet installed Specflow packages screenshot
我习惯了 Cucumber with IntelliJ,我们也有 SpecFlow C# Visual Studio 可以工作,但我就是无法连接到 Rider 中的步骤。
NB - 我试图在 Rider 中使用的项目正在 Visual Studio 中使用 Specflow。
还有其他人能够赢得这场战斗吗?
我很想听听。
谢谢
更新 @肯 感谢您的建议。
我尝试了以下两种方法:
- 在 feature.cs 的 .csproj 文件中手动添加 include 操作,但构建后仍然无法从功能中获取步骤。
- 包含范围(Feature="") 属性
但不幸的是,没有运气。
- Screenshot - feature and connected steps - Visual Studio
- 屏幕截图 - 功能和相关步骤 - Rider(包括 .csproj)
If this does not solve you problem, can you post the content of your .feature and .steps.cs files.
根据建议,下面是功能和 step.cs 文件的内容,它们在 VS 中正确映射。:
.特征
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
.步数
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 映射到 gherkin 库的插件,我很想听听。
我能想到的第一件事(我自己已经做过多次)是忘记 .steps.cs 文件中的 [Binding]
属性.哦,您可能还想标记一个 [Scope(Feature="")]
属性,只是为了避免歧义。
您可以做的另一件事(如果您使用的是 SpecFlow 3.0 及更高版本)是手动包含 .feature.cs 文件,看看是否能解决您的问题。如果是这样,我会考虑检查 .csproj 文件是否正确包含 .feature.cs 文件。
如果这不能解决您的问题,您可以 post 您的 .feature 和 .steps.cs[= 的内容吗? 43=] 个文件。
编辑 我从头开始,这些是我采取的步骤:
- 创建新解决方案
- 创建一个测试项目,select NUnit 作为测试框架
- 安装最新的 SpecFlow.NUnit 和 SpecFlow.Tools.MsBuild.Generation
- nuget 包(应该是版本 3.0.220)(这将自动安装正确的 SpecFlow nuget 包)
- 编辑 .csconfig 并添加
<Target Name="AfterUpdateFeatureFilesInProject">
<!-- include any generated SpecFlow files in the compilation of the project if not included yet -->
<ItemGroup>
<Compile Include="**\*.feature.cs" Exclude="@(Compile)" />
</ItemGroup>
</Target>
- 创建一个 .feature 文件并粘贴堆栈溢出问题中的内容
- 构建项目,这应该会在测试资源管理器中显示您的测试 运行 获得定义的测试
- 创建一个 class 以将定义放入(同样是 Binding 和 Scope 属性),从测试输出中复制这些定义 window
- 在 Given 方法中抛出异常
- 重新运行测试并查看是否抛出异常
PS: 你的秘密身份对我来说是安全的。 ;)