TestMethod正在使MSTest中的测试运行程序崩溃



我正在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:WINDOWSMicrosoft.NetassemblyGAC_32mscorlibv4.0_4.0.0.0__b77a5c561934e089mscorlib.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是罪魁祸首。记录器已初始化,需要在测试后正确清理。

[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");
}

最新更新