Unable to bind my feature to Steps using Specflow with JetBrains Rider

Viewed 3154

I've tried to set up JetBrains Rider with Specflow, following some of the guidance I found on the web:

... thank you for the documentation Ken.

However, I cannot get my scenario steps to link to any of my step files.


Setup

I believe that I have all the required NuGet packages installed for the latest version of SpecFlow

NuGet installed Specflow packages screenshot


I'm used to Cucumber with IntelliJ, and we have also got the SpecFlow C# Visual Studio working, but I just cannot get the scenario to connect to the steps in Rider.

NB - The project I am trying to use in Rider, is working in Visual Studio with Specflow.

Has anyone else been able to win this battle?

I'd love to hear how.

Thanks


Update @Ken Thank you for the suggestions.

I tried both of the following:

  1. Manually added include actions in .csproj file for feature.cs, but still unable to reach steps from feature after build.
  2. Included a Scope(Feature="") attribute

but unfortunately, no luck.

If this does not solve you problem, can you post the content of your .feature and .steps.cs files.

As suggested, below is the content of the feature and step.cs files, that do map correctly in VS.:

.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();
        }
    }
}

Thank you


Update - solved

OK, firstly, thank you Ken for the help and guidance. After following the steps Ken provides, creating a new project, and throwing the exception, I can confirm that .feature to step.cs binding works.

Ken, you are a gentleman and a genius. Thank you.

Secondly, I wrongly assumed that Rider would provide a way for me to navigate from the .feature to my Steps.cs code (Cucumber JVM style). I understand now that this is not yet supported by Rider.

  • this is why I thought the binding did not work !! Duh.

If anyone finds a plugin that maps the Rider gherkin to a gherkin library, I'd love to hear about it.


1 Answers

The first thing I can think of (which I have done multiple times myself) is to forget the [Binding] attribute in your .steps.cs file. Oh, and you might want to tag a [Scope(Feature="")] attribute as well, just to avoid ambiguity.

Another thing you can do (if you are using SpecFlow 3.0 and higher), is include the .feature.cs files manually and seeing if that fixes your problem. If that is the case, I would consider checking that the .csproj file has the correct includes for the .feature.cs files.

If this does not solve you problem, can you post the content of your .feature and .steps.cs files.

EDIT I started from scratch and these are the steps I took:

  1. Create a new solution
  2. Create a test project, select NUnit as testing framework
  3. Install the latest SpecFlow.NUnit and SpecFlow.Tools.MsBuild.Generation
  4. nuget packages (should be version 3.0.220) (this will automatically install the correct SpecFlow nuget package)
  5. Edit the .csconfig and add
<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>
  1. Create a .feature file and paste in the content from the stack overflow question
  2. Build the project, this should show your tests in the Test Explorer Run the tests to get their definitions
  3. Create a class to put the definitions into (again, Binding and Scope attribute), copy these definitions from the test output window
  4. Throw an Exception in the Given method
  5. Rerun the tests and see if the exception is thrown

PS: your secret identity is safe with me. ;)

Related