Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent 'Microsoft.VisualStudio.TestPlatform.ObjectModel.TestPlatformException: Could not find testhost' exception

I have a .NET 6.0 solution I use for automated UI testing of a web application. This solution consists of a number of projects, one of which contains all the tests, another being the logging implementation for the tests, and the others for other miscellaneous dependencies the framework has.

The project containing the tests uses NUnit as the test framework - it has the NuGet packages NUnit (3.13.3) and NUnit3TestAdapter (4.2.1). The logging project also includes the NUnit package because it uses the NUnit.Framework.TestContext to write out logs to the context of each test running.

I am using VS 2022 for the development of this solution. When I perform a build of the solution it will tell me the build succeeded (briefly flashing up in the bottom right) before immediately saying "Unexpected error detected. Check the Tests Output Pane for details.". If I check that I can see:

Test project MyNamespace.Logging does not reference any .NET NuGet adapter. Test discovery or execution might not work for this project.
It's recommended to reference NuGet test adapters in each test project in the solution.
========== Starting test discovery ==========
Microsoft.VisualStudio.TestPlatform.ObjectModel.TestPlatformException: Could not find testhost
   at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Hosting.DotnetTestHostManager.GetTestHostProcessStartInfo(IEnumerable`1 sources, IDictionary`2 environmentVariables, TestRunnerConnectionInfo connectionInfo)
   at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client.ProxyOperationManager.SetupChannel(IEnumerable`1 sources, String runSettings)
   at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client.ProxyDiscoveryManager.DiscoverTests(DiscoveryCriteria discoveryCriteria, ITestDiscoveryEventsHandler2 eventHandler)
NUnit Adapter 4.2.0.0: Test discovery starting
NUnit Adapter 4.2.0.0: Test discovery complete
========== Test discovery aborted: 60 Tests found in 1 sec ==========

So it's complaining that there is no test adaptor for my logging project. Of course I do not want or need an adaptor for this project as it legitimately contains no tests. Just to try and make some progress I installed the same NUnit adaptor as my test project uses. The error in the Test Output Pane then reduces to:

========== Starting test discovery ==========
Microsoft.VisualStudio.TestPlatform.ObjectModel.TestPlatformException: Could not find testhost
   at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Hosting.DotnetTestHostManager.GetTestHostProcessStartInfo(IEnumerable`1 sources, IDictionary`2 environmentVariables, TestRunnerConnectionInfo connectionInfo)
   at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client.ProxyOperationManager.SetupChannel(IEnumerable`1 sources, String runSettings)
   at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client.ProxyDiscoveryManager.DiscoverTests(DiscoveryCriteria discoveryCriteria, ITestDiscoveryEventsHandler2 eventHandler)
NUnit Adapter 4.2.0.0: Test discovery starting
NUnit Adapter 4.2.0.0: Test discovery complete
========== Test discovery aborted: 60 Tests found in 1.1 sec ==========

So installing the package clears the first part of it (but of course I don't really want to install it). I then had a read of the NUnit docs and found the NonTestAssembly attribute which seemed like it might be what I needed. I created an AssemblyInfo.cs file and added it in to the root of my logging project and then added the line [assembly: NUnit.Framework.NonTestAssembly] within it. Rebuilt the solution but the error remains as above. Does anyone know what I can do to get VS to be happy with this? Its frustrating as it shows the conical flask icon over my logging project which isn't ideal and then also makes it harder to see the 'Build succeeded' message as it's quickly overridden with the error.

Am I wrong to use the NUnit package as I am doing?

like image 506
mJ222398 Avatar asked Dec 06 '25 15:12

mJ222398


1 Answers

I had this same problem, but it went away when I added the Microsoft.NET.Test.Sdk package.

like image 63
Mike Avatar answered Dec 08 '25 07:12

Mike



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!