Using SpecFlow 3.0 with Rider

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 -->
        <Compile Include="**\*.feature.cs" Exclude="@(Compile)" />

The old SpecFlow version can add configuration tags in the .csproj file: <Generator>SpecFlowSingleFileGenerator</Generator>. They can easily be replaced by doing a search and replace (ctrl+h in rider) and using this regex to find all of them: \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.


Correctly unsubscribe in Angular

At work, a number of angular web pages were sending an increasing number of requests to the back-end. Apparently, if I reuse components that don’t properly dispose of their observable subscriptions, they keep sending and processing multiple requests.

Continue reading “Correctly unsubscribe in Angular”

I finally succumbed to the hype

My very first post on my very first blog. I’m kind of exited to share my views with the world and equally terrified that it’ll be complete gibberish. But only time will tell.

At the same time as this blog, I will be starting a side project (in my already busy life) to build a website to enter my fuel usage. But I want to experiment with a few things such as cloud (Azure and storage tables in specific), claim based auth, building an authenticated api, decoupled front end and back end, a javascript front-end framework (not sure which one yet) and maybe some things that will pop up while I build this site.

This blog will serve as a sort of journal where I describe how I set it up and how I build it. So you can expect my blog to be about this web site which I’ll start building one of these weeks. Yes, I said weeks. I told you my life is busy.