thomhurst / TUnit

A modern, fast and flexible .NET testing framework
MIT License
2.44k stars 39 forks source link

Test discovery fails on both VS/Rider text explorers with a freshly created test project #1336

Open kurabirko opened 4 hours ago

kurabirko commented 4 hours ago

Test discovery fails on both Rider and Visual Studio using the latest TUnit and .Net 9. I verified that MSTest works using Microsoft.Testing.Platform so I think this problem is related to TUnit. The built executable runs just fine, the problem is with the test explorers.

I have the follwowing project configuration with a single test method.

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net9.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="TUnit" Version="0.4.49" />
  </ItemGroup>

</Project>

Output pane in visual studio gives me the following exception.

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) in /_/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DotnetTestHostManager.cs:line 432
   at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client.ProxyOperationManager.SetupChannel(IEnumerable`1 sources, String runSettings) in /_/src/Microsoft.TestPlatform.CrossPlatEngine/Client/ProxyOperationManager.cs:line 226
   at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client.ProxyDiscoveryManager.InitializeDiscovery(DiscoveryCriteria discoveryCriteria, ITestDiscoveryEventsHandler2 eventHandler, Boolean skipDefaultAdapters) in /_/src/Microsoft.TestPlatform.CrossPlatEngine/Client/ProxyDiscoveryManager.cs:line 151
thomhurst commented 4 hours ago

https://thomhurst.github.io/TUnit/docs/tutorial-basics/running-your-tests#visual-studio

kurabirko commented 3 hours ago

Thanks for the solution. I'm normally using Rider though and installed Visual Studio just to verify this issue. I wouldn't have checked my visual studio setup were it not for you. Maybe adding this to the wiki might be nice?

thomhurst commented 2 hours ago

It is in both the documentation tutorial and the GitHub readme. There is a section for Rider too...

kurabirko commented 2 hours ago

I guess I wasn't really clear, apologies. I'm using Rider and "Build Tools for Visual Studio" to get some compilers etc. I did not have VS2022 before switching to TUnit. When I decided to go with TUnit I checked the documentation's rider section and switched the "Enable Testing Platform support" option. Test discovery was not working though. Then I installed VS2022, enabled the "Use testing platform server mode" option per your recommendation and everything started working. I this this particular behavior is not documented in the wiki, not the option in the rider settings. I don't know why the visual studio installation affected my rider setup though.

thomhurst commented 2 hours ago

The VS option isn't needed for Rider. It probably started working because you restarted your IDE, or re-built the project after switching it on. The project needs to be built first (after enabling the testing platform setting) for test discovery to kick in.