csf-dev / CSF.Screenplay

Implementation of the Screenplay pattern (aka Journey) in .NET
https://csf-dev.github.io/CSF.Screenplay/
MIT License
13 stars 1 forks source link

SpecFlow: Should be able to resolve ITestRunner #126

Closed craigfowler closed 6 years ago

craigfowler commented 6 years ago

Resolving an ITestRunner, for delegating to other step bindings, currently fails with an exception. This makes it impossible to delegate to other steps from within a given step.

Exception raised

Here's a sample test failure caused by this, taken from the Agiil project.

49) Error : Agiil.Tests.Tickets.ViewingTicketDetailsFeature.YoussefCanSeeTheTypeOfATicket
CSF.FlexDi.Resolution.ResolutionException : An exception occurred attempting to resolve an instance of `TechTalk.SpecFlow.ITestRunner' lazily.                                                                                   
Refer to the inner exception for further details.                                                                                                                                                                                
  ----> System.Reflection.TargetInvocationException : Exception has been thrown by the target of an invocation.                                                                                                                  
  ----> CSF.FlexDi.Resolution.CannotInstantiateTypeWithoutAnyConstructorsException : The type `TechTalk.SpecFlow.ITestRunner' must have at least one constructor.                                                                
Interfaces must be registered with a concrete implementation.                                                                                                                                                                    
  at CSF.FlexDi.Resolution.Proxies.LazyFactory+<>c__DisplayClass6_0`1[T].<CreateLazyObject>b__0 () [0x00039] in <531ce893e213434dbfd1037d37321336>:0                                                                             
  at System.Lazy`1[T].CreateValue () [0x00081] in <a07d6bf484a54da2861691df910339b1>:0                                                                                                                                           
  at System.Lazy`1[T].LazyInitValue () [0x00080] in <a07d6bf484a54da2861691df910339b1>:0                                                                                                                                         
  at System.Lazy`1[T].get_Value () [0x0003a] in <a07d6bf484a54da2861691df910339b1>:0                                                                                                                                             
  at Agiil.BDD.Bindings.Browsing.WebBrowsingSteps.GivenYoussefIsLoggedIntoAFreshlyInstalledSite () [0x00001] in <894ecc28e67e4368b7952ebbb6032746>:0                                                                             
  at (wrapper dynamic-method) System.Object:lambda_method (System.Runtime.CompilerServices.Closure,TechTalk.SpecFlow.Infrastructure.IContextManager)                                                                             
  at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&)                                                                                    
  at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00032] in <a07d6bf484a54da2861691df910339b1>:0                                                                                                                                                                                                  
  at TechTalk.SpecFlow.Bindings.BindingInvoker.InvokeBinding (TechTalk.SpecFlow.Bindings.IBinding binding, TechTalk.SpecFlow.Infrastructure.IContextManager contextManager, System.Object[] arguments, TechTalk.SpecFlow.Tracing.ITestTracer testTracer, System.TimeSpan& duration) [0x000f3] in <8c195ba137884726be2697e1899c5ddd>:0                                                                                                                             
  at TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.ExecuteStepMatch (TechTalk.SpecFlow.Bindings.BindingMatch match, System.Object[] arguments) [0x00076] in <8c195ba137884726be2697e1899c5ddd>:0                          
  at TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.ExecuteStep (TechTalk.SpecFlow.Infrastructure.IContextManager contextManager, TechTalk.SpecFlow.Bindings.StepInstance stepInstance) [0x0007d] in <8c195ba137884726be2697e1899c5ddd>:0                                                                                                                                                                                                                   
  at TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.OnAfterLastStep () [0x001f7] in <8c195ba137884726be2697e1899c5ddd>:0                                                                                                   
  at TechTalk.SpecFlow.TestRunner.CollectScenarioErrors () [0x00000] in <8c195ba137884726be2697e1899c5ddd>:0                                                                                                                     
  at Agiil.Tests.Tickets.ViewingTicketDetailsFeature.ScenarioCleanup () [0x00001] in <cb0901cc55a746138627c82f66f5dfe6>:0                                                                                                        
  at Agiil.Tests.Tickets.ViewingTicketDetailsFeature.YoussefCanSeeTheTypeOfATicket () [0x0004c] in <cb0901cc55a746138627c82f66f5dfe6>:0                                                                                          
  at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&)                                                                                    
  at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00032] in <a07d6bf484a54da2861691df910339b1>:0                                                                                                                                                                                                  
--TargetInvocationException                                                                                                                                                                                                      
  at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00048] in <a07d6bf484a54da2861691df910339b1>:0                                                                                                                                                                                                  
  at System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) [0x00000] in <a07d6bf484a54da2861691df910339b1>:0                                                                                       
  at System.Delegate.DynamicInvokeImpl (System.Object[] args) [0x000e7] in <a07d6bf484a54da2861691df910339b1>:0                                                                                                                  
  at System.MulticastDelegate.DynamicInvokeImpl (System.Object[] args) [0x00008] in <a07d6bf484a54da2861691df910339b1>:0                                                                                                         
  at System.Delegate.DynamicInvoke (System.Object[] args) [0x00000] in <a07d6bf484a54da2861691df910339b1>:0                                                                                                                      
  at CSF.FlexDi.Resolution.Proxies.LazyFactory+<>c__DisplayClass6_0`1[T].<CreateLazyObject>b__0 () [0x00000] in <531ce893e213434dbfd1037d37321336>:0                                                                             
--CannotInstantiateTypeWithoutAnyConstructorsException                                                                                                                                                                           
  at CSF.FlexDi.Resolution.ConstructorWithMostParametersSelector.AssertAConstructorIsFound (System.Type type, System.Reflection.ConstructorInfo ctor) [0x0001e] in <531ce893e213434dbfd1037d37321336>:0                          
  at CSF.FlexDi.Resolution.ConstructorWithMostParametersSelector.SelectConstructor (System.Type type) [0x00047] in <531ce893e213434dbfd1037d37321336>:0                                                                          
  at CSF.FlexDi.Registration.TypeRegistration.GetFactoryAdapter (System.Type type) [0x00000] in <531ce893e213434dbfd1037d37321336>:0                                                                                             
  at CSF.FlexDi.Registration.TypeRegistration.GetFactoryAdapter (CSF.FlexDi.Resolution.ResolutionRequest request) [0x00000] in <531ce893e213434dbfd1037d37321336>:0                                                              
  at CSF.FlexDi.Resolution.Resolver.Resolve (CSF.FlexDi.Resolution.ResolutionRequest request, CSF.FlexDi.Registration.IServiceRegistration registration) [0x00024] in <531ce893e213434dbfd1037d37321336>:0                       
  at CSF.FlexDi.Resolution.Resolver.CSF.FlexDi.Resolution.IResolvesRegistrations.Resolve (CSF.FlexDi.Resolution.ResolutionRequest request, CSF.FlexDi.Registration.IServiceRegistration registration) [0x00000] in <531ce893e213434dbfd1037d37321336>:0                                                                                                                                                                                                           
  at CSF.FlexDi.Resolution.Proxies.UnregisteredServiceResolverProxy.Resolve (CSF.FlexDi.Resolution.ResolutionRequest request) [0x00054] in <531ce893e213434dbfd1037d37321336>:0                                                  
  at CSF.FlexDi.Resolution.Proxies.CircularDependencyPreventingResolverProxy.Resolve (CSF.FlexDi.Resolution.ResolutionRequest request) [0x00023] in <531ce893e213434dbfd1037d37321336>:0 
  at CSF.FlexDi.Resolution.Proxies.LazyInstanceResolverProxy+<>c__DisplayClass3_0.<GetObjectFactory>b__0 () [0x0000b] in <531ce893e213434dbfd1037d37321336>:0 
  at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&)
  at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00032] in <a07d6bf484a54da2861691df910339b1>:0

Suspected root cause

The suspected root cause of this is that where I am hijacking SpecFlow's DI container, I'm not automatically registering all of the same things into it. Thus the test runner instance isn't being registered properly.

craigfowler commented 6 years ago

Workaround

Do not delegate to other steps via the test runner, instead resolve their bindings types and call the step manually.