C# 如何并行运行SpecFlow测试
我尝试使用NUnit测试运行程序并行运行SpecFlow测试。我正在使用:C# 如何并行运行SpecFlow测试,c#,unit-testing,.net-core,mstest,specflow,C#,Unit Testing,.net Core,Mstest,Specflow,我尝试使用NUnit测试运行程序并行运行SpecFlow测试。我正在使用: C#/.Net核心3.1 NUnit作为testrunner Specflow 我在一个文件的顶部添加了这一行(如下所述:): 测试开始并行执行,但立即抛出错误: Message: System.ArgumentException : An item with the same key has already been added. Key: NUnitTestProject1.SpecFlowFeatur
- C#/.Net核心3.1
- NUnit作为testrunner
- Specflow
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
我尝试不使用SpecFlow(仅使用原始NUnit),但效果很好。我也尝试了MSTest测试运行程序,但得到了相同的异常
我制作了一个非常小的示例项目,您可以在这里复制:
任何帮助都将不胜感激。:)
编辑:步骤的完整代码
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);
}
}
}
我用这个:
[assembly: Parallelizable(ParallelScope.Fixtures)]
那不是我想要的。我想并行运行所有测试。ParallelScope.Fixtures仅根据功能(类)并行运行测试。我想按照场景(方法)运行它们。您只能在这种并行模式下运行SpecFlow测试。一个功能中的场景将逐个执行。至于来自一个类的非specFlow测试:是的,它们可以并行运行。有官方的来源吗?我什么也找不到。为什么会这样?MSTest也是这样吗?检查这里:现在已经写了在方法级别执行不起作用。请在SpecFlowFeature1Steps中发布代码。这个答案()可以帮助您
[assembly: Parallelizable(ParallelScope.Fixtures)]