【发布时间】: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