首页 > 解决方案 > SpecFlow ISpecFlowOutputHelper 抛出 Unable to resolve service for type

问题描述

我正在使用 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()

请问有什么帮助吗?

标签: c#specflow

解决方案


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


推荐阅读