Generating SpecFlow files in Rider

Search for a command to run...

No comments yet. Be the first to comment.
Phew, that was a lot. I'm always surprised how simple solutions contain so much detail and nuance when I try to explain them. I hope I conveyed the message that A-Frame simplifies code within a module or class by separating the infrastructure compone...

No architecture is complete without an easy way to test the functionality. My recommended strategy is to use two types of tests: unit and integration. As far as test setup goes, there is no clear winner for a test framework. xUnit.NET, NUnit and the ...

The examples in the previous posts seem really nice for simple scenarios. How do I approach more advanced use cases? The big scenarios are: I need multiple pieces of data from different sources I need to perform an infrastructure call in the middle...

I’ve shown how I write code using the A-Frame architecture without help. Yet I find a library or framework very convenient when using advanced techniques. Wolverine is at its core a messaging framework, but goes well beyond that. It has an in-memory ...

Now the expected structure is clear, let's take a look at the code. I will start with a minimal API implementation to demonstrate that there is no need for a framework to implement this architecture. I do know of a framework that makes A-Frame effort...

At the moment, there is no official SpecFlow support in Jetbrains .net IDE Rider. I found a way to make it more bearable. Keep in mind that it's not a perfect solution.
After I install the SpecFlow nuget package, it downloads the SpecFlow executable that generates the .feature.cs files. Combined with the file watcher plugin, I can let the code behind files be generated. Go to Settings > Tools > File Watchers and click on the green + icon to add a custom file watcher.
Give the watcher an easy to understand name such as "SpecFlow file generation". Select the File Type "Cucumber Scenario". The Scope isn't really important, because the generator will refresh all .feature.cs files. I set the Scope to "Open files". The Program to run is situated in the folder "\packages\SpecFlow\tools\specflow.exe". The Arguments are "generateall $ProjectFileDir$\\.csproj". The last setting is Output paths to refresh and it should be "$ProjectFileDir$".
File Type: Cucumber Scenario
Scope: Open Files Program: <solution folder>\packages\SpecFlow<version>\tools\specflow.exe
Arguments: generateall $ProjectFileDir$\<TestProjectName>\<TestProjectName>.csproj
Output paths to refresh: $ProjectFileDir$

The "generateall" argument needs the test project .csproj file to see which cucumber files it needs to inspect to generated the .feature.cs files. The Output paths to refresh tells rider which folder to inspect after the program has run to detect which files are changed.
The biggest remaining problem for me is that there is no automatic steps generation. I usually start Visual Studio to generate the steps file the first time and then I manually edit the file whenever I update or add a step.
In my team, we use a Visual Studio tool to nest the .feature.cs and .steps.cs files. In Rider, there is an option to nest files. At the top right corner of the Solutions window, click the gear icon and select the File Nesting... menu item. Then click the + icon to add a new rule and add rules for both the feature.cs and .steps.cs files. It won't nest the files in the solution, it will just display them as nested. So Visual Studio won't nest the files, be aware of this.
It's not perfect and official support would be better, but it's a start. Now lets hope either Jetbrains or Specflow releases an official plugin for Rider so we can all enjoy SpecFlow as easily as it is in Visual Studio. If you want it to get here faster, start bothering both Jetbrains and SpecFlow about this.