22/09/2017

SpecFlow + .NET Core = problems

Home



Since I started using SpecFlow acceptance tests, I think that they are simply great. If I had to select whether to write only unit tests or only acceptance tests, I would select the latter. Nonetheless, there is one important problem with SpecFlow.

This problem is that SpecFlow officially doesn't support .NET Core projects. You can add *.feature files, which contain description of tests, to a .NET Core project, but SpecFlow will not generate code-behind code for them. Thankfully, I found a workaround. If you have the same problem, I recommend this 2 articles:
The first of these articles was written more than 1 ago so unfortunately it is not a temporary solution :( Briefly, the workaround is to use SpecFlow.NetCore package and add a pre-build step to the project.

However, it's not everything. I had a problem with this workaround. This problem was that the workaround worked properly on my machine but a build on the server was failing due to the following error:

error MSB3073: The command "dotnet SpecFlow.NetCore" exited with code -1

Does it say anything to you? Of course not but I found another error message in the log:

Can't find SpecFlow: C:\Users\SomeUser\.nuget\packages\SpecFlow\2.1.0\tools\specflow.exe Try specifying the path with --specflow-path

This explained a lot. But still it was strange because I installed all the dependencies via Nuget. Then I realized that I'm using newer version of SpecFlow i.e. 2.2.0 When I downgraded the problem disappered. Another solution, as error message suggests, is to run SpecFlow.NetCore with --specflow-path parameter. However, this requires modification of csproj and hardcoding a path. So select whichever you prefer.

At the end let's explain why the problem occured only on the build server? The answer is simple. My local Nuget cache contained both version of SpecFlow ;)


*The picture at the beginning of the post comes from own resources and shows a view from St. Peter's Basilica in the Vatican.

2 comments:

Peter said...

What exactly do you mean by downgrading? My thinking is that if you installed NuGet package 2.2.0, then so should the build, right?

Michał Komorowski said...

The problem was that when I use version 2.2.0 the Specflow Path was still:

"C:\Users\SomeUser\.nuget\packages\SpecFlow\2.1.0\tools\specflow.exe"

As you can see this path contains 2.1.0 instead of 2.2.0. I'm sorry but now I do not remember more details.

Post a Comment