【问题标题】:TestMethod is crashing the Test Runner in MSTestTestMethod 正在使 MSTest 中的测试运行程序崩溃
【发布时间】:2020-11-16 22:58:17
【问题描述】:

我正在 MSTest 中运行一组测试,在特定测试完成并运行 TestCleanup 后发生异常,这会导致测试运行程序崩溃并且不再运行任何测试。我有五个测试可以做到这一点,它们看起来与一些正确运行的测试几乎相同。

这是输出测试窗口中的错误:

[11/16/2020 5:36:14 PM Informational] ------ Run test started ------
[11/16/2020 5:36:55 PM Error] An exception occurred while invoking executor 'executor://mstestadapter/v2': Object reference not set to an instance of an object.
[11/16/2020 5:36:59 PM Informational] ========== Run test finished: 0 run (0:00:45.5280936) ==========

这是我在“输出调试”窗口中看到的:

Exception thrown: 'System.NullReferenceException' in log4net.dll
Exception thrown: 'System.NullReferenceException' in Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.dll
Exception thrown: 'System.NullReferenceException' in Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.dll
'testhost.x86.exe' (CLR v4.0.30319: Domain 3): Unloaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_32\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll'
…
The thread 0xdd68 has exited with code 0 (0x0).
Exception thrown: 'System.NullReferenceException' in Microsoft.TestPlatform.PlatformAbstractions.dll
The thread 0xdc80 has exited with code 0 (0x0).
The program '[57424] testhost.x86.exe' has exited with code 0 (0x0).

我可以看到 app.config 中的 log4net 设置为 OFF。导致测试运行程序崩溃的问题可能是什么?

【问题讨论】:

    标签: log4net mstest nullreferenceexception


    【解决方案1】:

    log4net 是罪魁祸首。记录器已初始化,需要在测试后正确清理。

      [TestCleanup]
      public virtual void TestCleanup()
      {
          //// To avoid this error caused by log4net v1.2.13: An exception occurred while invoking executor 'executor://mstestadapter/v1': Type is not resolved for member 'log4net.Util.PropertiesDictionary,log4net, Version=1.2.13.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a'.
          CallContext.FreeNamedDataSlot("log4net.Util.LogicalThreadContextProperties");
      }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-31
      • 1970-01-01
      • 1970-01-01
      • 2023-03-03
      相关资源
      最近更新 更多