[SpecFlow] System.Exception:Unit test Provider already set.

497 views
Skip to first unread message

Carl Blanchard

unread,
May 4, 2019, 12:10:01 PM5/4/19
to SpecFlow
I've created a brand new .net 2.1 NUnit test project. 

Added the following NuGet packages 

NUNit 3.11.0
SpecFlow 3.0.199
SpecFlow.NUnit.Runners 3.0.199
SpecFlow.Tools.MsBuild.Generation 3.0.199
SpecRun.SpecFlow 3.0.329

Created one feature file with a test and I always get the build error 

[SpecFlow] System.Exception:Unit test Provider already set. 

Does anyone have any ideas ???

2019-05-04_170518.png


Stefan Zivkovic

unread,
May 4, 2019, 3:33:39 PM5/4/19
to spec...@googlegroups.com
This happens to me if I try build. Notice the specFlow version - 1.9.0.77. This is a NUnit project for .NET Core 2.1 framework with latest specFlow v3.0.199. Previously, I had one Class Library project for .NET 4.6.1 framework with specFlow v2.4.1, building fine.
image.png

image.png

Following the https://specflow.org/documentation/Generate-Tests-from-MsBuild/, I tried to remove CustomTool, but still nothing - bad .feature.cs file is generated. Also, file TechTalk.SpecFlow.targets  is mentioned in link, but couldn't find it, maybe due to I already had set specFlow v2.4.1 for another project (exists in specflow\2.4.1, but not for specflow\3.0.199). The given error navigates me to SpecFlow.Tools.MsBuild.Generation.targets file inside C:\Users\Name\.nuget\packages\specflow.tools.msbuild.generation\3.0.199\build.

--
You received this message because you are subscribed to the Google Groups "SpecFlow" group.
To unsubscribe from this group and stop receiving emails from it, send an email to specflow+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Thomas Marinich

unread,
Jun 5, 2019, 9:23:15 AM6/5/19
to SpecFlow
I'm getting the same issue. The problem is with Specflow 3+ you can't have more than 1 unit test provider. You have NUnit and Specrun, In my project, I have MSTest and SpecRun. I want both so that I can access TestContext but I get this same error.

I'm looking for a way around this but have come up empty.

Eddy Jones

unread,
Jun 5, 2019, 9:38:24 AM6/5/19
to spec...@googlegroups.com
You are getting the error because you have two tuners in your setup. The SpecRun.SpecFlow and the SpecFlow.NUnit.Runner... you'll have to choose which runner you want to use.


From: spec...@googlegroups.com <spec...@googlegroups.com> on behalf of Thomas Marinich <thomas....@gmail.com>
Sent: Wednesday, June 5, 2019 6:23:14 AM
To: SpecFlow
Subject: [specflow] Re: [SpecFlow] System.Exception:Unit test Provider already set.
 
--
You received this message because you are subscribed to the Google Groups "SpecFlow" group.
To unsubscribe from this group and stop receiving emails from it, send an email to specflow+u...@googlegroups.com.

Thomas Marinich

unread,
Jun 5, 2019, 10:15:56 AM6/5/19
to SpecFlow
I know that is the error but I need to runners. I need MSTest to access TestContext and I want to use SpecRun. Before Specflow 3.0 you could specify your unittestprovider as both with "SpecRun+MStest".

All I want is to use SpecRun with TestContext. Is there a way to do that with Specflow 3.0?


On Saturday, May 4, 2019 at 12:10:01 PM UTC-4, Carl Blanchard wrote:

Eddy Jones

unread,
Jun 5, 2019, 10:45:10 AM6/5/19
to spec...@googlegroups.com
As far as I know, no. But I could be wrong. I have all of my unit tests that test my test framework written in xunit. But I too needed the TestContext so I had to move my unit tests to their own project (which is better design anyway) and converted my specflow tests to MSTest.

According to your includes, though you aren't using an MSTest ringer. I only see nunit and specrun. The msbuild only handles the code behind generation of the feature.cs files.

Sent: Wednesday, June 5, 2019 7:15:56 AM
To: SpecFlow
Subject: [specflow] Re: [SpecFlow] System.Exception:Unit test Provider already set.
 
--
You received this message because you are subscribed to the Google Groups "SpecFlow" group.
To unsubscribe from this group and stop receiving emails from it, send an email to specflow+u...@googlegroups.com.

Andreas Willich

unread,
Jun 5, 2019, 11:59:56 AM6/5/19
to SpecFlow
SpecRun+MSTest in SpecFlow 2.4 and before generated code-behind code for SpecRun and MSTest.
You have then every scenario twice in the test explorer.
One will be executed via MSTest, one will be executed with the SpecFlow+Runner (aka SpecRun).

Thomas: Which functionality do you want to use from the MSTest TestContext?


Thomas Marinich

unread,
Jun 5, 2019, 12:25:52 PM6/5/19
to SpecFlow
I want to extract the properties from the runsettings files. I m tasked with updating our already existing TCs written in MStest to Specflow using Specflow+ (SpecRun). We want to use SpecRun because we like its features but I also want to keep intact the functionality TestContext that defines our test settings.I got it working with the nuget package
 Specflow.MSTest but as soon as I add SpecRun, I get the above error.

I just want access to the TestContext in the following code:

        [BeforeScenario("LoginSmokeTest")]
        public void TestSetup(TestContext context)
        {
             Setup(context);
            TestContext = context; // Had to do this myself

.
.
.

Thanks!
Tom

On Saturday, May 4, 2019 at 12:10:01 PM UTC-4, Carl Blanchard wrote:
Reply all
Reply to author
Forward
0 new messages