Reputation: 79
I'm trying to setup a basic project in C# with Visual Studio 2017 that runs tests using specflow 3 and nunit. I had previously worked with specflow version 2.4.1 and the setup and running the tests was easy. However I keep getting errors while trying to setup specflow 3 with nunit.
I tried following the steps here: https://specflow.org/getting-started/
The furthest I have gotten is the below error.
[SpecFlow] System.Exception: Unit test Provider already set.
Also my code behind is NOT generating, but I have installed the nuget package SpecFlow.Tools.MsBuild.Generation which is supposed to generate the backend for the feature files.
Anyone know how I can get a C# project going with Specflow 3 and Nunit?
Upvotes: 1
Views: 7781
Reputation: 1
I had the very same issue yesterday on VS 2022. I tried many stuff from this forum and other sources, but only the following steps helped me...
I have done:
Since I am using C#12 /.Net8, I had to install the newest extension from the official repository, which has not been released so far (for some strange reason):
https://github.com/SpecFlowOSS/SpecFlow/issues/2726#issuecomment-1831457636
The old extension version in nuget is not compatible with .Net8 so far.
After these steps, the solution starts to work.
Upvotes: 0
Reputation: 71
@Nkosi - I ran into the same issue as you have described with the same error message. However in my case, I was using MSTest unittest and SpecRun.SpecFlow. This is how I solved the problem in my case.
Now re-build the project and you should be able to see the Specflow tests written in your test explorer window.
Upvotes: 3
Reputation: 9
@Nkosi You might have already have more than one unit test provider package installed. Delete any specflow related like specflow.specrun, specrun.runner packages and Make sure you have installed the following packages if already exists re-install it again.
And remove the Remove “SpecFlowSingleFileGenerator” from the Custom Tool field in the Properties of your feature files.
Add this target to the project file as per the spcflow documentation https://specflow.org/2019/updating-to-specflow-3/
You can then able to see the tests in test explorer pane.I have run into the similar issues but I did re-installed the packages as I mentioned above that fixed the issues.Hope that helps!.
Upvotes: 0
Reputation: 156
SpecFlow 3 no longer uses the app.config. You need to use a specflow.json file which is mandatory.
Make sure you have the following Nuget libraries included:
Make sure you created a basic specflow.json file ...
{ "bindingCulture": { "language" :"en-us" }, "language": { "feature": "en-us" }, "plugins": [] }
... and you should be good to go.
Upvotes: 0
Reputation: 187
Check your app.config and remove nodes referring to specflow and nunit. Also go to your existing .feature files, right-click, Properties. Leave Custom Tool blank.
Upvotes: 0
Reputation: 2519
I hit this problem when adding both the specflow.xunit nuget package and the specflow+ runner nuget package. Removing the specflow+ runner package enabled me to build and run the tests with xunit.
Upvotes: 2