【发布时间】:2020-01-10 13:18:37
【问题描述】:
首先我的设置:
- .Net Core 3.1(从 2.2 迁移而来)
- xUnit 2.4.1
- xUnit Runner 2.4.1
- Visual Studio 2019 16.4.2
- Test.SDK 16.4.0
我刚刚从 .Net Core 2.2 迁移到 3.1。我刚刚修复了错误并将我的序列化程序更改为 System.Text。我的应用运行良好,但是...
注意:我所有的测试都是使用
WebApplicationFactory的集成测试。
我一直使用 Visual Studio Test Runner 来运行所有测试,但是当我尝试 Run All 时出现错误:
请注意奇怪的
netcoreapp2.2,而我专门在 MyTests 和 MyApp 项目中使用 .Net Core 3.1。
[10.01.2020 2:05:03.939 PM] System.InvalidOperationException: The following TestContainer was not found 'D:\Projects\MyApp\MyTests\bin\Debug\netcoreapp2.2\GrabGoApiTests.dll'
at Microsoft.VisualStudio.TestWindow.Client.TestContainer.TestContainerProvider.<GetTestContainerAsync>d__46.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.VisualStudio.TestWindow.Controller.TestContainerConfigurationQueryByTestsBase.<QueryTestContainerConfigurationsAsync>d__6.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.VisualStudio.TestWindow.Controller.TestContainerConfigurationQuery.<GetTestContainerConfigurationsAsync>d__16.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.VisualStudio.TestWindow.Controller.TestRunConfiguration.<UpdateAsync>d__13.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.VisualStudio.TestWindow.Controller.RunOperation.<RunTestsAsync>d__15.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.VisualStudio.TestWindow.Controller.Operation.<<Execute>b__37_0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.VisualStudio.TestWindow.Extensibility.ILoggerExtensions.<CallWithCatchAsync>d__10`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at Microsoft.VisualStudio.Telemetry.WindowsErrorReporting.WatsonReport.GetClrWatsonExceptionInfo(Exception exceptionObject)
然后我在想“好吧......也许 VS 再次表现得很奇怪,我会尝试从控制台运行测试”
PS D:\Projekty\GrabGoAPI> dotnet test
Test run for D:\Projects\MyApp\MyTests\bin\Debug\netcoreapp3.1\GrabGoApiTests.dll(.NETCoreApp,Version=v3.1)
Microsoft (R) Test Execution Command Line Tool Version 16.3.0
Copyright (c) Microsoft Corporation. All rights reserved.
Starting test execution, please wait...
A total of 1 test files matched the specified pattern.
The active test run was aborted. Reason: Test host process crashed : Stack overflow.
Test Run Aborted.
Total tests: Unknown
Passed: 101
Total time: 26,3009 Seconds
现在我在这里。
我找到了that。但我无法在 Visual Studio 中调试测试以找出导致问题的测试。
还有dotnet test --blame 每次都指责随机测试。
如何找到导致 StackOverflow 异常的原因?
【问题讨论】:
-
测试通常不会按照特定的顺序执行,通常会在调用堆栈达到其限制时产生stackoverflow异常。这两件事结合起来可以解释这个问题。恕我直言,这里有几个可能的原因:a)递归和b)大量测试。很难用提供的信息来判断。
-
测试使用 .Net Core 2.2。只有 267 个测试。所以不是很多。也许问题出在 System.Text JsonSerializer 中的某个地方……我不知道……
标签: c# asp.net-core xunit dotnet-test