1
votes

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?

5
Compare your project against the example project provided by TechTalk. Make sure you have all the packages necessary and that the project file looks correct in general. - Mika Sundland

5 Answers

3
votes

@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.

  1. Since we use MSTest we had the following nuget packages installed pertaining to MSTest (MSTest.TestAdapter & MSTest.TestFramework ) and also had SpecFlow.MsTest. I went ahead and uninstalled all these nugetpackages from nuget package manager and its dependencies.
  2. Now install SpecRun.Runner package alone which will inturn pull its other dependencies. As highlighted below, it has the SpecRun.NUnit packages as well. enter image description here

Now re-build the project and you should be able to see the Specflow tests written in your test explorer window.

2
votes

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.

0
votes

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.

0
votes

@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.

  • NUnit
  • NUnit3TestAdapter
  • SpecFlow
  • SpecFlow.Nunit
  • SpecFlow.Tools.MsBuild.Generation

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/

Target xml code snippet

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!.

-1
votes

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:

  • Microsoft.NET.Test.Sdk
  • NUnit
  • SpecFlow
  • SpecFlow.NUnit
  • SpecFlow.Tools.MsBuild.Generation

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.