Michael Sync

Michael Sync

Crisp, minimal personal blog

04 Sep 2021

TestPlatformException - Can't run the xunit test on Visual Studio 2019?


Problem

I have the .NET core 3.1 class library project that I want to add my xunit tests. I installed xunit 2.4.1, xunit.runner.visualstudio (2.4.1). I added two sample tests. When I run the tests from Visual Studio Test explorer, I am getting this error.

Error in finding the xunit tests on Visual Studio 2019

Error Message

Log level is set to Informational (Default). Test data store opened in 0.195 sec. ========== Starting test discovery ========== Microsoft.VisualStudio.TestPlatform.ObjectModel.TestPlatformException: Unable to find C:..\Tests\bin\Debug\netcoreapp3.1\testhost.dll. Please publish your test project and retry. at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Hosting.DotnetTestHostManager.GetTestHostPath(String runtimeConfigDevPath, String depsFilePath, String sourceDirectory) at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Hosting.DotnetTestHostManager.GetTestHostProcessStartInfo(IEnumerable1 sources, IDictionary2 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) ========== Test discovery aborted: 0 Tests found in 631.6 ms ==========

Solution

The solution is that you need to install Microsoft.TestPlatform.TestHost nuget package.

Test Platform Test Host - Visual Studio

  • Microsoft.TestPlatform.TestHost is the test host obviously. It supports running tests written in several test frameworks using the pluggable adapter model. You can read more about that here https://github.com/microsoft/vstest/.
  • xunit is my preferred unit test framework.
  • xunit.runner.visualstudio is the test adapter that connects between xunit and VSTest host.