A while ago, I wrote about using SpecFlow with JetBrains IDE Rider. Recently, SpecFlow updated their version to 3.0 and it brings some different behaviour with it. After using it for a while, I really like the new flow.
The first change is that I need to install three packages, instead of two. SpecFlow and a unit testing framework (MSTest, NUnit or xUnit) still need to be installed. Additionally, SpecFlow.Tools.MsBuild.Generation needs to be installed as well.
The biggest benefit of the SpecFlow.Tools.MsBuild.Generation nuget is that I don’t need to set up a file writer anymore. I do need to update the .csproj file to include some configuration. The whole process is nicely documented on the SpecFlow site, but I’ll give the basics here.

First, right click on the test project and choose Edit > Edit MyProject.csproj option. Then just paste in the next bit of XML:
<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>
The old SpecFlow version can add configuration tags in the .csproj file:
. They can easily be replaced by doing a search and replace (ctrl+h in rider) and using this regex to find all of them: <Generator>SpecFlowSingleFileGenerator</Generator>
.\n[ ]+SpecFlowSingleFileGenerator
Save the .csproj file and just build the project. The .feature.cs files will be generated next to the .feature files. You can include them in the project, but the build server will update the generated files when it builds the project anyway. So you don’t need to include the .feature.cs files in the project anymore if you don’t want to.
Happy coding and keep those tests green!
Update: I got some feedback that it isn’t intuitive to find the Given/When/Then declarations for the .feature.cs file. All I need to do is run the tests. The method definitions appear in the test output window. If I add a new line, I just rerun the test. The test will be marked incomplete with the new method signature in the test output window. All that’s left to do is to copy and paste the signatures into the right file and flesh out the new method. Oh, and don’t forget to add Binding
and Scope
attribute on the class. I’ve forgotten that more times than I dare to admit.
Hi, Ken
Thanks a lot for your article 🙂
*feature.cs files are generated correctly. Is there a way to generate *.steps.cs files automatically too?
For now I need to run tests, than copy generated code for *.steps.cs from failed tests console output – it’s look weird…
LikeLike
Hey Name-With-Characters-Not-On-My-Keyboard 🙂
This is unfortunately the way to go, I do the same. Since there is no SpecFlow plugin for Rider (yet), you can’t generate the *.steps.cs files. Maybe there is a command line thing you could fabricate. I haven’t put time in that yet, anyway.
The problem (at least the last time I checked) is that JetBrains doesn’t want to make and maintain an unofficial plugin that will only be used by a few users. SpecFlow doesn’t want to invest time into a niche userbase that uses the Rider IDE. They have enough work with VS plugin to keep them busy. So I understand why they both don’t want to put the effort. At the time I write this, this is the best workaround there is.
LikeLike
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 (only run unit tests optiion) 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
LikeLike
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.
LikeLike
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.
LikeLike