visual-studio-2022test-explorer

Visual Studio 2022 - Test Explorer says Test run finished but tests are not executed


I am upgrading to VS2022 from VS2019. We had some 1000+ test cases already written which we are able to execute on VS2017 and VS2019 but when I open the project in VS2022, test cases do not run. It takes less than a millisecond and the status bar says "Test run finished 0 tests, (0 passed, 0 failed, 0 skipped run in <1 ms

There is 1 error icon reported on Text Explorer ad after cligking that icon or when I try to "debug" an individual test, I get following error in the Output window

Building Test Projects
Starting test discovery for requested test run
========== Starting test discovery ==========
System.IO.FileNotFoundException: Could not load file or assembly 'System.Text.Json, Version=4.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The system cannot find the file specified.
File name: 'System.Text.Json, Version=4.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'
   at Microsoft.Extensions.DependencyModel.DependencyContextJsonReader.Read(Stream stream)
   at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Hosting.DotnetTestHostManager.GetTestHostPath(String runtimeConfigDevPath, String depsFilePath, String sourceDirectory) in /_/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DotnetTestHostManager.cs:line 763
   at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Hosting.DotnetTestHostManager.GetTestHostProcessStartInfo(IEnumerable`1 sources, IDictionary`2 environmentVariables, TestRunnerConnectionInfo connectionInfo) in /_/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DotnetTestHostManager.cs:line 289
   at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client.ProxyOperationManager.SetupChannel(IEnumerable`1 sources, String runSettings) in /_/src/Microsoft.TestPlatform.CrossPlatEngine/Client/ProxyOperationManager.cs:line 223
   at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client.ProxyDiscoveryManager.InitializeDiscovery(DiscoveryCriteria discoveryCriteria, ITestDiscoveryEventsHandler2 eventHandler, Boolean skipDefaultAdapters) in /_/src/Microsoft.TestPlatform.CrossPlatEngine/Client/ProxyDiscoveryManager.cs:line 149

WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].

========== Test discovery aborted: 0 Tests found in 15.6 ms ==========
========== Starting test run ==========
========== Test run finished: 0 Tests (0 Passed, 0 Failed, 0 Skipped) run in < 1 ms ==========

The projects in the solution are in .Net Core 3.1

What I have tried so far

System Info: Microsoft Visual Studio Professional 2022 (64-bit) Version 17.7.1 (latest) OS Name Microsoft Windows Server 2019 Standard Version 10.0.17763 Build 17763

Cam anyone put me in the right direction please?


Solution

  • I encountered this problem as well, when I upgraded from Visual Studio 17.6.6 to 17.7.1.

    I upgraded the "Microsoft.NET.Test.Sdk" NuGet package to 17.7.1 (previously I was using 16.4.0), which resolved the issue and allowed me to run the tests in Visual Studio again.