【问题标题】:SpecFlow ISpecFlowOutputHelper throws Unable to resolve service for typeSpecFlow ISpecFlowOutputHelper 抛出 Unable to resolve service for type
【发布时间】:2021-11-13 21:59:24
【问题描述】:

我正在使用 Specflow+livingDoc 进行报告。 并且正在测试 API,但报告没有提到发送的请求和响应。所以我在想是否有办法添加到 LivingDoc 报告中,我发现了这个:https://docs.specflow.org/projects/specflow/en/latest/outputapi/outputapi.html

我将它注入到 stepdefs 构造函数中

private readonly ISpecFlowOutputHelper _specFlowOutputHelper;

        public StepDefs(ScenarioContext scenarioContext, IHttpClientFactory httpClientFactory, ISpecFlowOutputHelper outputHelper)
        {
            _scenarioContext = scenarioContext;
            _httpClientFactory = httpClientFactory;
            _specFlowOutputHelper = outputHelper;
        }

但是当我尝试运行场景时,我得到了这个异常:

Message: 
    System.InvalidOperationException : Unable to resolve service for type 'TechTalk.SpecFlow.Infrastructure.ISpecFlowOutputHelper' while attempting to activate 'AcceptanceTests.Steps.StepDefs'.

  Stack Trace: 
    CallSiteFactory.CreateArgumentCallSites(Type serviceType, Type implementationType, CallSiteChain callSiteChain, ParameterInfo[] parameters, Boolean throwIfCallSiteNotFound)
    CallSiteFactory.CreateConstructorCallSite(ResultCache lifetime, Type serviceType, Type implementationType, CallSiteChain callSiteChain)
    CallSiteFactory.TryCreateExact(ServiceDescriptor descriptor, Type serviceType, CallSiteChain callSiteChain, Int32 slot)
    CallSiteFactory.TryCreateExact(Type serviceType, CallSiteChain callSiteChain)
    CallSiteFactory.CreateCallSite(Type serviceType, CallSiteChain callSiteChain)
    <>c__DisplayClass7_0.<GetCallSite>b__0(Type type)
    ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
    CallSiteFactory.GetCallSite(Type serviceType, CallSiteChain callSiteChain)
    ServiceProviderEngine.CreateServiceAccessor(Type serviceType)
    ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
    ServiceProvider.GetService(Type serviceType)
    DependencyInjectionTestObjectResolver.ResolveBindingInstance(Type bindingType, IObjectContainer scenarioContainer)
    lambda_method58(Closure , IContextManager , String )
    BindingInvoker.InvokeBinding(IBinding binding, IContextManager contextManager, Object[] arguments, ITestTracer testTracer, TimeSpan& duration)
    TestExecutionEngine.ExecuteStepMatch(BindingMatch match, Object[] arguments, TimeSpan& duration)
    TestExecutionEngine.ExecuteStep(IContextManager contextManager, StepInstance stepInstance)
    TestExecutionEngine.OnAfterLastStep()
    TestRunner.CollectScenarioErrors()
    Feature.ScenarioCleanup()

有什么帮助吗?

【问题讨论】:

  • 您为此项目安装了哪些 NuGet 包?
  • SolidToken.Specflow.DependencyInjection, SpecFlow.Plus.LivingDocPlugin, SpecFlow.xUnit

标签: c# specflow


【解决方案1】:

我必须在我的启动服务中注册这个接口,现在它可以正常工作了。

【讨论】:

  • 您能否补充一些细节,您是如何注册接口的?那么未来的人能理解这个答案吗?
  • 同意@TheTanic。回答你自己的问题是完全可以的。我以前用自己的问题做过这个。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-10-06
  • 2022-07-07
  • 2014-02-08
  • 2017-09-30
  • 2019-05-30
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多