4

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.


Peter Parker
  • 43
  • 1
  • 4
  • This is quite strange. I have created a Sample.feature file, copied in your content and after a build it showed me the test, I could run it and get the steps generated. Then I added a steps file, copied in the generated content and replaced the first `ScenarioContext.Current.Pending();` with a `throw new Exception("this is my exception");`. When I run, it nicely throws the exception. What is your SpecFlow version and your Rider version? I use SpecFlow 3.0.220 and Rider 2019.1.2. – Ken Bonny Jun 23 '19 at 19:30
  • Hi Ken, I think there was a bug between my keyBoard and myChair (me). After following your excellent instructions and explanation, I understand now that Binding works, tests run, and there is no UI method to get from .feature to steps. Thats cool. Thank you so much. You are a legend. – Peter Parker Jun 25 '19 at 18:02

1 Answers1

2

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

Ken Bonny
  • 729
  • 1
  • 9
  • 29
  • Thank you. Update provided as suggested. – Peter Parker Jun 22 '19 at 22:37
  • All clear now Ken. My reputaitonisn't enough to register a visble PLUS vote, but you definitely get one for helping. Thank you. – Peter Parker Jun 25 '19 at 18:05
  • No problem, happy to help. :) – Ken Bonny Jun 26 '19 at 07:04
  • @KenBonny Thanks for all help. But I have one more question. do you run your tests from .feature files or .feature.cs files? .feature.cs files are undebuggable and when I click on .feature file I get "Please specify non-empty path to cucumber project". I do not want to launch all tests in project just to debug one, so I really want launch specifc feature file. – Nickname0222022022 Oct 26 '19 at 08:05
  • I use the `8: Unit Tests` tab at the bottom. They automatically appear there after a build or `Run All`. There I can choose which test to run, set up automatic run on build and start/debug one or more tests. – Ken Bonny Oct 28 '19 at 09:03