【问题标题】:Specflow overwriting original exception stack traceSpecflow 覆盖原始异常堆栈跟踪
【发布时间】:2019-05-04 14:06:59
【问题描述】:

你们中有人知道可以关闭标题中提到的行为的解决方法吗?每次我在测试步骤中出错时,异常如下所示:

Test method 
FunctionalTests.Features.Parties.PartyAddingFeature.FeatureTitle threw exception: 
TechTalk.SpecFlow.BindingException: Error calling binding method 'FunctionalTests:FunctionalTests.Steps.PartiesSteps.GivenLegacyPartyUpsertedIntegrationEventCameInWithData(String, Table)': Object of type 'System.String' cannot be converted to type 'System.Int32'.
    at TechTalk.SpecFlow.Bindings.BindingInvoker.InvokeBinding(IBinding binding, IContextManager contextManager, Object[] arguments, ITestTracer testTracer, TimeSpan& duration) in D:\a\1\s\TechTalk.SpecFlow\Bindings\BindingInvoker.cs:line 69
   at TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.ExecuteStepMatch(BindingMatch match, Object[] arguments) in D:\a\1\s\TechTalk.SpecFlow\Infrastructure\TestExecutionEngine.cs:line 395
   at TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.ExecuteStep(IContextManager contextManager, StepInstance stepInstance) in D:\a\1\s\TechTalk.SpecFlow\Infrastructure\TestExecutionEngine.cs:line 316
   at TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.OnAfterLastStep() in D:\a\1\s\TechTalk.SpecFlow\Infrastructure\TestExecutionEngine.cs:line 132
   at FunctionalTests.Features.Parties.PartyAddingFeature.ScenarioCleanup()
   at FunctionalTests.Features.Parties.PartyAddingFeature.FeatureTitle() in C:\Project\test\Services\FunctionalTests\Features\Parties\PartyAdding.feature:line 25

【问题讨论】:

  • 您能发布发生这种情况的场景和绑定吗?我认为此错误更多地与将参数转换为步骤中的错误有关。
  • 它与转换参数有很大关系,但这不是这里的问题:) 问题是我的步骤包含几个我进行转换(或应该做一个)的地方,但问题是是堆栈跟踪没有指向特定位置,这意味着 specflow 框架已经吞下了原始异常并用它自己的堆栈跟踪覆盖了它。我正在寻找一种方法来制作应有的堆栈跟踪。

标签: c# specflow functional-testing


【解决方案1】:

您认为,对于这种情况,什么应该是正确的例外? 我的意思是,我们看不到或不知道您的代码。通过您发布的堆栈跟踪,它表明您在输入 Given/when/then 方法之一之前存在参数转换的情况。

【讨论】:

  • 正确的堆栈跟踪应该指向代码中实际发生异常的位置,对吧?它指向一些BindingInvoker 方法,该方法位于正确位置的一半:)
  • 真的很容易重现。只需在您的步骤中的某处抛出一个异常 - 您不会在那里看到完整的堆栈跟踪,但与我的类似,细微的差别将是您的步骤的名称和异常消息。
猜你喜欢
  • 2014-01-12
  • 2011-01-05
  • 1970-01-01
  • 2017-08-06
  • 2010-09-13
  • 1970-01-01
  • 1970-01-01
  • 2018-07-19
相关资源
最近更新 更多