小编Ila*_*lan的帖子

单击测试在"全部运行"上失败,但未在"运行所选测试"中全部选中

我有一些奇怪的行为.如果我在测试资源管理器中单击"全部运行",则单元测试中的一个会失败,但如果我选择所有测试并单击"运行选定的测试",则单元测试通过.

失败的测试是抛出一个反射错误:System.Reflection.TargetException: Non-static method requires a target.在我正在测试的DLL代码中定义的类型.这个类似乎没有什么奇怪的东西 - 在dll中定义了很多其他类,反映很满意.我在下面列出了测试堆栈跟踪.

NB这是一个复杂的测试 - 它从.xlsx文件读取输入和预期答案,使用xlsx中的数据填充LocalDb,使用LocalDB中的数据执行计算,然后比较计算值和预期值.但是正如我所说,当我运行所有测试时(使用select all> Run Selected Test),它正在工作并且有效.

Run All有什么不同?任何见解将不胜感激.

我试过一个没有运气的清洁和重建.捕获和记录反射错误表示GetValue调用正在为我尝试访问该类型的每个属性抛出 - 但仅在由"全部运行"运行且仅在此类型上运行时?(如果我发现错误,那么所有其他类型的GetValues都会成功).

堆栈跟踪

Test Name:  IT_CheckCashOnly1DepositOutputValues
Test FullName:  Lib.AE.Tests.Integration.CalculationTests.IT_CheckCashOnly1DepositOutputValues
Test Source:    c:\netreturn.co.za\Main\NetReturn\Lib.AE.Tests\IntegrationTests\CalculationTest.cs : line 23
Test Outcome:   Failed
Test Duration:  0:00:00.1661906

Result Message: 
Test method Lib.AE.Tests.Integration.CalculationTests.IT_CheckCashOnly1DepositOutputValues threw exception: 
System.Reflection.TargetException: Non-static method requires a target.
Result StackTrace:  
at System.Reflection.RuntimeMethodInfo.CheckConsistency(Object target)
at System.Reflection.RuntimeMethodInfo.InvokeArgumentsCheck(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, …
Run Code Online (Sandbox Code Playgroud)

.net unit-testing exception-handling visual-studio-2012

30
推荐指数
2
解决办法
2万
查看次数

删除匹配定位器的父级

有没有办法根据子属性定位节点?或删除匹配节点的父节点?

我需要运行web.config转换来删除以下的第二个<dependentAssembly>:

<runtime>
 <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
  <!-- Don't want to delete this one -->
  <dependentAssembly>
    <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35"/>
    <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0"/>
  </dependentAssembly>
  <!-- This is the one I want to delete -->
  <dependentAssembly>
    <assemblyIdentity name="Microsoft.VisualStudio.Enterprise.AspNetHelper" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
    <codeBase version="11.0.0.0" href="file:///C:/Program%20Files%20(x86)/Microsoft%20Visual%20Studio%2011.0/Common7/IDE/PrivateAssemblies/Microsoft.VisualStudio.Enterprise.AspNetHelper.DLL"/>
  </dependentAssembly>
 </assemblyBinding>
</runtime>
Run Code Online (Sandbox Code Playgroud)

查找<assemblyIdentity>很简单,但我需要删除父<dependentAssembly>(和<codeBase>).如果有一个"xdt:Transform ="RemoveParent"这将成功,但AFAIK没有.

或者,如果有一个Locator我可以在<dependentAssembly>上使用,它可以匹配孩子,那么这也可以.

web-config-transform

5
推荐指数
1
解决办法
587
查看次数