Skip to content

Commit

Permalink
Fix WinUI MSTest runner sample
Browse files Browse the repository at this point in the history
  • Loading branch information
Evangelink committed Nov 15, 2024
1 parent e8d4e7b commit bd6cd38
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,23 @@ void OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventArgs args)

// Replace back with e.Arguments when https://github.com/microsoft/microsoft-ui-xaml/issues/3368 is fixed
#if MSTEST_RUNNER
// Ideally we would want to reuse the generated main so we don't have to manually handle all dependencies
// but this type is generated too late in the build process so we fail before.
// You can build, inspect the generated type to copy its content if you want.
// await TestingPlatformEntryPoint.Main(Environment.GetCommandLineArgs().Skip(1).ToArray());
try
{

string[] cliArgs = Environment.GetCommandLineArgs().Skip(1).ToArray();
// Ideally we would want to reuse the generated main so we don't have to manually handle all dependencies
// but this type is generated too late in the build process so we fail before.
// You can build, inspect the generated type to copy its content if you want.
// await TestingPlatformEntryPoint.Main(Environment.GetCommandLineArgs().Skip(1).ToArray());
string[] cliArgs = Environment.GetCommandLineArgs()
.Skip(1)
.Where(arg => !arg.Contains("EnableMSTestRunner"))
.ToArray();
ITestApplicationBuilder builder = await TestApplication.CreateBuilderAsync(cliArgs);

// Or alternatively, we would want to use AddSelfRegisteredExtensions but we have the same issue.
//builder.AddSelfRegisteredExtensions(cliArgs);
Microsoft.Testing.Platform.MSBuild.TestingPlatformBuilderHook.AddExtensions(builder, cliArgs);
Microsoft.Testing.Extensions.Telemetry.TestingPlatformBuilderHook.AddExtensions(builder, cliArgs);
TestingPlatformBuilderHook.AddExtensions(builder, cliArgs);
Microsoft.VisualStudio.TestTools.UnitTesting.TestingPlatformBuilderHook.AddExtensions(builder, cliArgs);
using ITestApplication app = await builder.BuildAsync();
await app.RunAsync();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,7 @@
<PackageReference Include="Microsoft.TestPlatform.TestHost" Version="$(VSTestVersion)" Condition=" '$(EnableMSTestRunner)' != 'true' " />
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.5.240428000" />
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.22621.3233" />

<!-- We cannot use the v$(MSTestVersion) has it contains a bug in how the targets are importing the dll for WinUI -->
<PackageReference Include="MSTest.Analyzers" Version="$(MSTestVersion)">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="MSTest.TestAdapter" Version="$(MSTestVersion)" />
<PackageReference Include="MSTest.TestFramework" Version="$(MSTestVersion)" />
<PackageReference Include="MSTest" Version="$(MSTestVersion)" />
</ItemGroup>

<!--
Expand Down

0 comments on commit bd6cd38

Please sign in to comment.