specflow - 无法使用 Specflow 和 JetBrains Rider 将我的功能绑定(bind)到 Steps

标签 specflow rider

我尝试使用 Specflow 设置 JetBrains Rider,遵循我在网上找到的一些指导:

  • generating-specflow-files-in-rider
  • using-specflow-3-0-with-rider
  • specflow-steps-generation-and-general-rider-changes

  • ...感谢您提供文档 Ken。

    但是,我无法将我的场景步骤链接到我的任何步骤文件。

    设置

    我相信我已经为最新版本的 SpecFlow 安装了所有必需的 NuGet 包

    NuGet installed Specflow packages screenshot

    我已经习惯了使用 IntelliJ 的 Cucumber,而且我们还让 SpecFlow C# Visual Studio 正常工作,但我只是无法让场景连接到 Rider 中的步骤。

    备注 - 我尝试在 Rider 中使用的项目正在使用 Specflow 在 Visual Studio 中工作。

    有没有其他人能够赢得这场战斗?

    我很想听听如何。

    谢谢

    更新
    @肯
    感谢您的建议。

    我尝试了以下两种方法:
  • 在 .csproj 文件中为 feature.cs 手动添加了包含操作,但在构建后仍然无法从功能到达步骤。
  • 包含 Scope(Feature="") 属性

  • 但不幸的是,没有运气。
  • Screenshot - feature and connected steps - Visual Studio
  • Screenshot - feature and connected steps - Rider (including .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 绑定(bind)有效。

    肯,你是一位绅士和天才。谢谢你。

    其次,我错误地认为 Rider 会为我提供一种从 .feature 导航到我的 Steps.cs 代码(Cucumber JVM 风格)的方法。我现在知道 Rider 尚不支持此功能。
  • 这就是为什么我认为绑定(bind)不起作用的原因!呃。

  • 如果有人找到将 Rider 小 cucumber 映射到小 cucumber 库的插件,我很想听听。

    最佳答案

    我能想到的第一件事(我自己已经做过多次)是忘记 [Binding] .steps.cs 文件中的属性。哦,你可能想标记一个 [Scope(Feature="")] 属性也是如此,只是为了避免歧义。

    您可以做的另一件事(如果您使用的是 SpecFlow 3.0 及更高版本),是手动包含 .feature.cs 文件并查看是否可以解决您的问题。如果是这种情况,我会考虑检查 .csproj 文件是否包含正确的 .feature.cs 文件。

    如果这不能解决您的问题,您能否发布 .feature 和 .steps.cs 文件的内容。

    编辑
    我从头开始,这些是我采取的步骤:

  • 创建新的解决方案
  • 创建一个测试项目,选择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 文件并粘贴堆栈溢出问题中的内容
  • 构建项目,这应该在测试资源管理器中显示您的测试
    运行测试以获取它们的定义
  • 创建一个类以将定义放入(同样,Binding 和 Scope 属性),从测试输出窗口复制这些定义
  • 在 Given 方法中抛出异常
  • 重新运行测试并查看是否抛出异常


  • PS:你的 secret 身份对我来说是安全的。 ;)

    关于specflow - 无法使用 Specflow 和 JetBrains Rider 将我的功能绑定(bind)到 Steps,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56715659/

    相关文章:

    c# - 无法在 Jetbrains Rider 上运行空的 Android 应用程序

    c# - 在 .NET(或一般)中创建文档的正确方法是什么?

    visual-studio-2013 - 即使通过 NuGet 安装,SpecFlow 也找不到包

    c# - Specflow:步骤的基类

    c# - 如何从 Visual Studio 2012 中的 resharper 测试 session 窗口导航到功能文件?

    c# - Rider - 将匿名函数 block 参数与函数调用保持在同一行

    nunit - 带有 NUnit 的 Specflow 不尊重 TestFixtureSetUpAttribute

    c# - Protractor 结合 SpecFlow、Selenium 和 C#

    mysql - 如何让 MySQL.Data 在 Rider 上运行?

    c# - 在 Rider 中添加用于测试的资源文件