I try to run SpecFlow tests with NUnit test runner in parallel. I am using:
- C# / .Net Core 3.1
- NUnit as testrunner
- Specflow
I have added this line on top of a file (as describe here: https://specflow.org/documentation/parallel-execution/):
[assembly: Parallelizable(ParallelScope.All)]
Tests start to execute in parallel but immediately throw an error:
Message:
System.ArgumentException : An item with the same key has already been added. Key: NUnitTestProject1.SpecFlowFeature1Steps
Stack Trace:
Dictionary`2.TryInsert(TKey key, TValue value, InsertionBehavior behavior)
Dictionary`2.Add(TKey key, TValue value)
TypeRegistration.Resolve(ObjectContainer container, RegistrationKey keyToResolve, ResolutionList resolutionPath)
ObjectContainer.ResolveObject(RegistrationKey keyToResolve, ResolutionList resolutionPath)
ObjectContainer.Resolve(Type typeToResolve, ResolutionList resolutionPath, String name)
ObjectContainer.Resolve(Type typeToResolve, String name)
TestObjectResolver.ResolveBindingInstance(Type bindingType, IObjectContainer container)
lambda_method(Closure , IContextManager , Int32 )
BindingInvoker.InvokeBinding(IBinding binding, IContextManager contextManager, Object[] arguments, ITestTracer testTracer, TimeSpan& duration)
TestExecutionEngine.ExecuteStepMatch(BindingMatch match, Object[] arguments)
TestExecutionEngine.ExecuteStep(IContextManager contextManager, StepInstance stepInstance)
TestExecutionEngine.OnAfterLastStep()
TestRunner.CollectScenarioErrors()
SpecFlowFeature1Feature.ScenarioCleanup()
SpecFlowFeature1Feature.AddTwoNumbers() line 8
I tried without SpecFlow (just raw NUnit) and it worked. I also tried with MSTest test runner but got the same exception.
I have made a very tiny example project which you can clone here: https://github.com/davidguidali/specflowerror
Any help would be appreciated. :)
EDIT: Full code of steps
using NUnit.Framework;
using System;
using System.Threading;
using TechTalk.SpecFlow;
[assembly: Parallelizable(ParallelScope.All)]
namespace NUnitTestProject1
{
[Binding]
public class SpecFlowFeature1Steps
{
[Given(@"test(.*)")]
public void GivenTest(int p0)
{
Thread.Sleep(5000);
Assert.IsTrue(true);
}
}
}