Search code examples
visual-studio-2019googletest

Visual Studio 2019 Test Explorer exception (The following TestContainer was not found - GetTestContainerAsync)


I have a solution in Visual Studio 2019 Professional (16.4.2) that contains various test executables (Google Test and NUnit).

When trying to launch the tests from Test Explorer, I sometimes get an error about a particular test container not being found. The strange thing is, the container it complains about belongs to a different build configuration. For example, running tests in x64|Debug results in an error about missing x64|Release container. In any case, the test container it complains about is always at the reported location.

For good measure I have tried deleting all outputs, restarting Visual Studio, rebuilding everything (including the apparently unnecessary test container) and relaunching the test run, but the error persists and prevents any tests from running. It would seem Test Explorer is caching some state from a previous test run and getting it mixed up with the current run.

Here's an example stack trace when trying to run tests in x64 Debug. Notice how the error pertains to the x64 Release build of the container:

Test Adapter for Google Test: Test discovery starting...
Found 99 tests in executable C:\ProjectTest\Output\x64\Debug\BatchA\TestSuite.BatchA.exe
Test discovery completed, overall duration: 00:00:00.3742589

[30/06/2020 1:44:22.976 PM] ========== Discovery finished: 99 tests found (0:00:01.9392922) ==========
System.InvalidOperationException: The following TestContainer was not found 'C:\ProjectTest\Output\x64\Release\BatchA\TestSuite.BatchA.exe'
   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.TestContainerConfigurationQueryByTestsBase.<GetContainersToUpdateInternalAsync>d__3.MoveNext()

... Followed by a lot more TestWindow.*MoveNext() stack trace entries similar to the ones above

If I switch back to the platform and configuration mentioned in the container error, sometimes it will successfully launch the tests, but other times it complains about some other container (again, one from an apparently unrelated build configuration).

For now I've given up and gone back to running tests in 2017 which seems to be working for now, although if it starts happening there as well I'll really be stuck. I'd like to avoid defaulting my Visual Studio settings if possible, as I have a lot of things set up that took a while to configure.

Thank you.


Solution

  • Tested with Visual Studio 2019:

    1. Close Visual Studio.

    2. Open File Explorer and go to the folder containing your solution. In here there is a folder .vs\solution name\v16\TestStore containing numbered folders.

    3. Delete the numbered folders.

    Note: Some files being deleted may remain locked for a few seconds after closing Visual Studio as it takes a while for all sub processes to terminate, so you may need to retry a few times.