0

First my setup:

  • .Net Core 3.1 (migrated from 2.2)
  • xUnit 2.4.1
  • xUnit Runner 2.4.1
  • Visual Studio 2019 16.4.2
  • Test.SDK 16.4.0

I've just migrated from .Net Core 2.2 to 3.1. I just fixed errors and changed my serializer to System.Text. My app is working just fine but...

Note: All my tests are integration tests which are using WebApplicationFactory.

I was always using Visual Studio Test Runner to run all tests, but then when I tried to Run All I got an error:

Notice that strange netcoreapp2.2, while I'm specifically using .Net Core 3.1 in MyTests and MyApp project.

[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)

And then I was thinking "Okay... Maybe VS is acting strange again I'll try running tests from console"

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

And now I'm here.

I found that. But I cannot Debug tests in Visual Studio to find out which tests are causing the problem.

Also dotnet test --blame are blaming random tests every time.

How can I find what is causing that StackOverflow exception?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Morasiu
  • 1,204
  • 2
  • 16
  • 38
  • 1
    Test usually are not executed in an specific order, and an stackoverflow exception is usually generated when the call stack has reached its limit. Both things combined could explain the problem. IMHO a couple of possible causes here: a) recursion and b) huge amount of tests. Hard to tell with the info provided. – Cleptus Jan 10 '20 at 13:53
  • Tests were working with .Net Core 2.2. There are only 267 tests. So it's not a lot. Maybe the problem is somewhere within the System.Text JsonSerializer... I don't know... – Morasiu Jan 10 '20 at 13:56

3 Answers3

3

I got this error, it was caused by a method that was calling itself after some refactoring, so thank you test.

Olaj
  • 1,782
  • 4
  • 19
  • 36
1

I was due to System.Text.Json not handling Reference Loop as JSON.Net did.

Change to JSON.Net helped.

Morasiu
  • 1,204
  • 2
  • 16
  • 38
0

I solved this issue by installing the Microsoft.NET.Test.Sdk.

  1. Open the Tools tab
  2. Choose the NuGet Package Manager sub-menu
  3. Click on the Manage NuGet packages for solution menuitem
  4. Install the Microsoft.NET.Test.Sdk
Peter Csala
  • 17,736
  • 16
  • 35
  • 75