错误运行specflow Xamarin测试时无法解析原始类型或结构

时间:2017-01-17 17:30:01

标签: c# android xamarin specflow

我正在尝试使用与Xamarin集成的SpecFlow。在测试期间,我能够安装应用程序(* .apk)并çanch它进入登录页面,但后来我得到错误:

BoDi.ObjectContainerException was unhandled by user code
HResult=-2146233088
Message=Primitive types or structs cannot be resolved: Xamarin.UITest.Platform (resolution path: VVM_SpecFlow.LoginApplicationSteps)
  Source=TechTalk.SpecFlow
  StackTrace:
   at BoDi.ObjectContainer.ResolveObject(RegistrationKey keyToResolve, ResolutionList resolutionPath)
   at BoDi.ObjectContainer.Resolve(Type typeToResolve, ResolutionList resolutionPath, String name)
   at BoDi.ObjectContainer.<>c__DisplayClass53_0.<ResolveArguments>b__0(ParameterInfo p)
   at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()
   at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
   at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
   at BoDi.ObjectContainer.ResolveArguments(IEnumerable`1 parameters, RegistrationKey keyToResolve, ResolutionList resolutionPath)
   at BoDi.ObjectContainer.CreateObject(Type type, ResolutionList resolutionPath, RegistrationKey keyToResolve)
   at BoDi.ObjectContainer.TypeRegistration.Resolve(ObjectContainer container, RegistrationKey keyToResolve, ResolutionList resolutionPath)
   at BoDi.ObjectContainer.ResolveObject(RegistrationKey keyToResolve, ResolutionList resolutionPath)
   at BoDi.ObjectContainer.Resolve(Type typeToResolve, ResolutionList resolutionPath, String name)
   at BoDi.ObjectContainer.Resolve(Type typeToResolve, String name)
   at TechTalk.SpecFlow.Infrastructure.BindingInstanceResolver.ResolveBindingInstance(Type bindingType, IObjectContainer scenarioContainer)
   at lambda_method(Closure , IContextManager )
   at TechTalk.SpecFlow.Bindings.BindingInvoker.InvokeBinding(IBinding binding, IContextManager contextManager, Object[] arguments, ITestTracer testTracer, TimeSpan& duration)
   at TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.ExecuteStepMatch(BindingMatch match, Object[] arguments)
   at TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.ExecuteStep(StepInstance stepInstance)
   at TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.OnAfterLastStep()
   at TechTalk.SpecFlow.TestRunner.CollectScenarioErrors()
   at VVM___SpecFlow.LoginApplicationFeature.ScenarioCleanup()
   at VVM___SpecFlow.LoginApplicationFeature.LoginWithValidCredentials() in <……..\SpecFlowFeature1.feature:line> 12
  InnerException:  a

我相信在specflow读取要素文件后会发生这种情况。

有人可以帮我吗?

2 个答案:

答案 0 :(得分:2)

您的LoginApplicationSteps有一个带参数Xamarin.UITest.Platform的构造函数。这是一种让你烦恼的原始类型 SpecFlow有一个集成的DI框架,用于解析绑定类。它使用构造函数注入。在您的情况下,它正在搜索平台枚举的注册,这不起作用。 解决方案是将枚举包装在一个类中并在BeforeScenario挂钩中注册它(参见链接文档页面上的高级选项)。

DI-框架的文档(在SpecFlow中称为上下文注入)在这里:http://specflow.org/documentation/Context-Injection/

答案 1 :(得分:0)

如果有人在步骤类之间使用BoDi作为容器,这是我解决原始类型的解决方法:

var test = (string)objectContainer.Resolve<object>("testString");