c# - 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()
请问有什么帮助吗?
解决方案
我必须在我的启动服务中注册这个接口,现在它工作正常。
推荐阅读
- python - 如何修复递归函数
- c# - 缩放一组多边形以监控 WPF 中的分辨率
- logging - F# 的新手 - 通过类绑定 (>>=!) 中缀运算符和引号进行不显眼的日志记录?
- c# - 如何计算在mongodb和c#中有db的时间和速度的积分
- elasticsearch - ElasticSearch 如何处理包含 230m 条目的索引?
- asp.net-mvc - 制作没有视图或控制器的 asp.net razor 模板
- c++ - 将 cctype 函数分配给 std::function,gcc 编译错误
- javascript - 正则表达式电子邮件检查器不起作用,正则表达式忽略点
- jupyter-notebook - JupyterLab 未加载环境变量
- mysql - 复杂的更新查询