Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Testing platform server mode breaks testing #4808

Closed
daryllabar opened this issue Jan 27, 2025 · 8 comments
Closed

Use Testing platform server mode breaks testing #4808

daryllabar opened this issue Jan 27, 2025 · 8 comments
Labels
Area: Testing Platform Belongs to the Microsoft.Testing.Platform core library External: Test Explorer Resolution: By Design

Comments

@daryllabar
Copy link

Describe the bug

Upon updating to the latest version of VS, my test explorer has stopped running tests.

Steps To Reproduce

Enable Use Testing platform server mode

Expected behavior

My tests run

Actual behavior

Here are the logs:

[1/27/2025 11:53:08.392 AM]  Launching test runner 'C:\_dev\MyClient\dynamics-box\CRM\Server\MyClient.Dataverse.Plugin.Tests\bin\Debug\MyClient.Dataverse.Plugin.Tests.dll'
[1/27/2025 11:53:08.393 AM]  Logging diagnostics under 'C:\_dev\MyClient\dynamics-box\CRM\Server\MyClient.Dataverse.Plugin.Tests\bin\Debug\Log'
[1/27/2025 11:53:08.393 AM]  Created TCP listener with port 0 for program 1
[1/27/2025 11:53:08.394 AM]  Starting test runner 'C:\Program Files\dotnet\dotnet.exe C:\_dev\MyClient\dynamics-box\CRM\Server\MyClient.Dataverse.Plugin.Tests\bin\Debug\MyClient.Dataverse.Plugin.Tests.dll  --server --diagnostic --diagnostic-verbosity Debug --diagnostic-output-directory "C:\_dev\MyClient\dynamics-box\CRM\Server\MyClient.Dataverse.Plugin.Tests\bin\Debug\Log" --results-directory "C:\_dev\MyClient\dynamics-box\CRM\Server\TestResults" --client-port 50491'
[1/27/2025 11:53:08.409 AM] [Error] Unable to connect to testing platform runner process 'C:\_dev\MyClient\dynamics-box\CRM\Server\MyClient.Dataverse.Plugin.Tests\bin\Debug\MyClient.Dataverse.Plugin.Tests.dll'.

When trying to run the test in the command line, I get a different error, not sure if it is because I need to start a TCP listener first?

C:\Users\Me>"C:\Program Files\dotnet\dotnet.exe" "C:\_dev\MyClient\dynamics-box\CRM\Server\MyClient.Dataverse.Plug
in.Tests\bin\Debug\MyClient.Dataverse.Plugin.Tests.dll"  --server --diagnostic --diagnostic-verbosity Debug --diagnostic-output-directory "C:\_dev\MyClient\dynamics-box\CRM\Server\MyClient.Dataverse.Plugin.Tests\bin\Debug\Log" --results-directory "C:\_dev\MyClient\dynamics-box\CRM\Server\TestResults" --client-port 50491
A fatal error was encountered. The library 'hostpolicy.dll' required to execute the application was not found in 'C:\_dev\MyClient\dynamics-box\CRM\Server\MyClient.Dataverse.Plugin.Tests\bin\Debug\'.
Failed to run as a self-contained app.
  - The application was run as a self-contained app because 'C:\_dev\MyClient\dynamics-box\CRM\Server\MyClient.Dataverse.Plugin.Tests\bin\Debug\MyClient.Dataverse.Plugin.Tests.runtimeconfig.json' was not found.
  - If this should be a framework-dependent app, add the 'C:\_dev\MyClient\dynamics-box\CRM\Server\MyClient.Dataverse.Plugin.Tests\bin\Debug\MyClient.Dataverse.Plugin.Tests.runtimeconfig.json' file and specify the appropriate framework.

Additional context

I'm testing a .Net 4.6.2 project with the following nuget packages with "test" in their name installed:

Image

Unchecking the preview feature and restarting VS resolves the issue.

@Youssef1313
Copy link
Member

cc @drognanar

@Youssef1313 Youssef1313 added the Area: Testing Platform Belongs to the Microsoft.Testing.Platform core library label Jan 27, 2025
@drognanar
Copy link
Member

If this is a net4.6.2 project then it cannot be run via dotnet.exe, @Evangelink are testing platform projects generating an executable for netfx by default?

otherwise @daryllabar could you check if setting <OutputType>Exe</OutputType> in the csproj ends up generating an executable? (C:_dev\MyClient\dynamics-box\CRM\Server\MyClient.Dataverse.Plugin.Tests\bin\Debug\MyClient.Dataverse.Plugin.Tests.exe). if the exe is present it should be run instead

@daryllabar
Copy link
Author

@drognanar it is not generating an exe.

@Evangelink
Copy link
Member

@daryllabar I am assuming your project looks roughly like:

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

  <PropertyGroup>
    <TargetFramework>net462</TargetFramework>
    <LangVersion>latest</LangVersion>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
    <EnableMSTestRunner>true</EnableMSTestRunner>
	<!--<OutputType>Exe</OutputType>-->
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="MSTest" Version="3.7.3" />
  </ItemGroup>

</Project>

If that's the case then the behavior is "expected". As explained in our documentations and blogposts you need to set both EnableMSTestRunner and OutputType for the behavior to be correct.

@Youssef1313 This is an example of where adding a target that warns when output type is not set to exe and enable mstest runner is set could be useful.

Closing as by-design.

@Evangelink Evangelink closed this as not planned Won't fix, can't repro, duplicate, stale Jan 28, 2025
@Youssef1313
Copy link
Member

@Evangelink Interesting. At least for .NET Framework seems like dotnet exec on libraries don't work (that seems to work for .NET Core)

@Evangelink
Copy link
Member

Yes that's what I have seen. Not sure if that's expected dotnet behavior but I wouldn't be surprised there is a fundamental change in assembly layout.

@daryllabar
Copy link
Author

@Youssef1313 What blog posts / documentation are you referring to? All I know is I updated my Visual Studio and my unit tests failed to run.

I've updated my test project to this:

<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
	<PropertyGroup>
		<AssemblyName>MyClient.Dataverse.Plugin.Tests</AssemblyName>
		<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
		<DebugType>pdbonly</DebugType>
		<DebugSymbols>true</DebugSymbols>
		<RootNamespace>MyClient.Dataverse.Plugin.Tests</RootNamespace>
		<TargetFramework>net462</TargetFramework>
		<SignAssembly>false</SignAssembly>
		<LangVersion>9</LangVersion>
		<EnableMSTestRunner>true</EnableMSTestRunner>
		<OutputType>Exe</OutputType>
	</PropertyGroup>
	<ItemGroup>
	  <ProjectReference Include="..\MyClient.Dataverse.Plugin\MyClient.Dataverse.Plugin.csproj" />
	  <ProjectReference Include="..\MyClient.Dataverse.Test\MyClient.Dataverse.Test.csproj" />
	</ItemGroup>
</Project>

which does generate the exe,

But now I get a new error:

Unhandled Exception: System.InvalidOperationException: The test framework adapter has not been registered. Use 'ITestApplicationBuilder.RegisterTestFramework' to register it
   at Microsoft.Testing.Platform.Builder.TestApplicationBuilder.<BuildAsync>d__30.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at TestingPlatformEntryPoint.<Main>d__0.MoveNext() in C:\_dev\MyClient\dynamics-box\CRM\Server\MyClient.Dataverse.Plugin.Tests\obj\Debug\TestPlatformEntryPoint.cs:line 14
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at TestingPlatformEntryPoint.<Main>(String[] args)

@Evangelink
Copy link
Member

What blog posts / documentation are you referring to

https://devblogs.microsoft.com/dotnet/introducing-ms-test-runner/
https://learn.microsoft.com/en-us/dotnet/core/testing/unit-testing-mstest-runner-intro

All I know is I updated my Visual Studio and my unit tests failed to run.

How did you onboard to MSTest runner? The csproj change is not linked to VS update and does require some manual onboarding which you probably did at some point.

But now I get a new error:

@daryllabar Where are MSTest package references?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Testing Platform Belongs to the Microsoft.Testing.Platform core library External: Test Explorer Resolution: By Design
Projects
None yet
Development

No branches or pull requests

4 participants