Open grootstebozewolf opened 3 years ago
Error:
Message:
Test method Example.Features.SomeGivenStep threw exception:
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.MissingFieldException: Field not found: 'SimpleInjector.Lifestyle.Singleton'.
Stack Trace:
SimpleInjectorPlugin.RegisterSpecFlowDependencies(IObjectContainer objectContainer, Container container)
<>c__DisplayClass1_0.<Initialize>b__2()
--- End of inner exception stack trace ---
RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
Delegate.DynamicInvokeImpl(Object[] args)
ObjectContainer.InvokeFactoryDelegate(Delegate factoryDelegate, ResolutionList resolutionPath, RegistrationKey keyToResolve) line 827
FactoryRegistration.Resolve(ObjectContainer container, RegistrationKey keyToResolve, ResolutionList resolutionPath) line 411
ObjectContainer.ResolveObject(RegistrationKey keyToResolve, ResolutionList resolutionPath) line 779
ObjectContainer.Resolve(Type typeToResolve, ResolutionList resolutionPath, String name) line 698
ObjectContainer.Resolve[T](String name) line 673
ObjectContainer.Resolve[T]() line 666
SimpleInjectorTestObjectResolver.ResolveBindingInstance(Type bindingType, IObjectContainer scenarioContainer)
lambda_method(Closure , IContextManager )
BindingInvoker.InvokeBinding(IBinding binding, IContextManager contextManager, Object[] arguments, ITestTracer testTracer, TimeSpan& duration) line 69
TestExecutionEngine.ExecuteStepMatch(BindingMatch match, Object[] arguments) line 517
TestExecutionEngine.ExecuteStep(IContextManager contextManager, StepInstance stepInstance) line 422
TestExecutionEngine.OnAfterLastStep() line 203
TestRunner.CollectScenarioErrors() line 59
ExampleFeature.ScenarioCleanup()
ExampleFeature.SomeGivenStep() line 6
Tried to upgrade to the latest versions of SpecFlow and SimpleInjector.
Ammended the Example project
using SimpleInjector;
using SpecFlow.SimpleInjector;
namespace MyCalculator.Specs.Support
{
public static class TestDependencies
{
[ScenarioDependencies]
public static Container CreateContainerBuilder()
{
// create container with the runtime dependencies
var builder = Dependencies.CreateContainerBuilder();
builder.Options.ResolveUnregisteredConcreteTypes = true;
//TODO: add customizations, stubs required for testing
return builder;
}
}
}
After this, the teardown gave this error:
AddTwoNumbers
Source: Addition.feature line 7
Duration: 2 min
Message:
TestCleanup method MyCalculator.Specs.Features.AdditionFeature.TestTearDown threw exception. System.InvalidOperationException: System.InvalidOperationException: Collection was modified; enumeration operation may not execute..
Stack Trace:
ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource)
Enumerator.MoveNext()
<OfTypeIterator>d__95`1.MoveNext()
WhereEnumerableIterator`1.MoveNext()
ObjectContainer.Dispose()
InternalContextManager`1.DisposeInstance()
InternalContextManager`1.Cleanup()
ContextManager.CleanupScenarioContext()
TestExecutionEngine.OnScenarioEnd()
TestRunner.OnScenarioEnd()
AdditionFeature.TestTearDown()
And additional info:
-> Loading plugin C:\Users\_behbloemscheerj\Source\Repos\SpecFlow.SimpleInjector\sample\MyCalculator\MyCalculator.Specs\bin\Debug\net48\SpecFlow.SimpleInjector.SpecFlowPlugin.dll
-> Loading plugin C:\Users\_behbloemscheerj\Source\Repos\SpecFlow.SimpleInjector\sample\MyCalculator\MyCalculator.Specs\bin\Debug\net48\TechTalk.SpecFlow.MSTest.SpecFlowPlugin.dll
-> Loading plugin C:\Users\_behbloemscheerj\Source\Repos\SpecFlow.SimpleInjector\sample\MyCalculator\MyCalculator.Specs\bin\Debug\net48\MyCalculator.Specs.dll
-> Missing [assembly:RuntimePlugin] attribute in MyCalculator.Specs, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null. Please check https://go.specflow.org/doc-plugins for details.
-> Using specflow.json
Given I have entered 50 into the calculator
-> done: CalculatorSteps.GivenIHaveEnteredIntoTheCalculator(50) (0.4s)
And I have entered 70 into the calculator
-> done: CalculatorSteps.GivenIHaveEnteredIntoTheCalculator(70) (0.0s)
When I press add
-> done: CalculatorSteps.WhenIPressAdd() (0.0s)
Then the result should be 120 on the screen
-> done: CalculatorSteps.ThenTheResultShouldBeOnTheScreen(120) (72.7s)
Steps to reproduce
Create a .Net Framework test project (MSBuild)
Ammended the app.config
Created a simple test feature file and implemented the steps, then created a step implementation where I inject the scenarioContext:
Bound the container in a TestDependencies support class