Repository navigation
Support testing unpackaged WinUI apps under Microsoft.Testing.Platform - #10330
Conversation
Addresses the unpackaged half of #2784 for Microsoft.Testing.Platform. Make the PackagedApp launcher layout-aware. Its ITestHostLauncher was enabled for every Windows run, and an enabled launcher forces the platform onto the out-of-process test host controller model and copies the whole build output into a temp deployment directory. That is right for a packaged (MSIX) app, which cannot be started in place, but pure overhead for an unpackaged one. It now enables only when the layout really is packaged, so referencing the package from an unpackaged app costs nothing. TESTINGPLATFORM_PACKAGEDAPP_LAUNCHER (auto|always|never) overrides the probe, and the manifest search is bounded so an unrelated ancestor manifest cannot misclassify an app. Fix a deadlock in UITestMethodAttribute. An empty catch swallowed failures while bringing the application up, leaving the TaskCompletionSource incomplete so the blocking wait never returned: the run hung forever with no diagnostic. This is what an unpackaged app hits when the Windows App SDK runtime cannot be resolved. Failures now propagate, the UI thread dying counts as a failure (XAML tears that thread down for some native failures without any managed exception), an overall timeout bounds the wait, and the reflection wrapper is unwrapped so the reported message is the real cause. Startup is serialized, since Application.Start can only run once per process, and the failure is remembered so later tests report the same cause. Add an unpackaged sample and end-to-end acceptance tests that build real Windows App SDK apps, plus docs covering packaged versus unpackaged, the self-hosted versus WinUITestTarget wiring, and how the bootstrapper is initialized. Also publish the run's exit code from the samples: the WinUI-generated entry point is void, so without assigning Environment.ExitCode a test app always exits 0 and failing tests never fail the build. Co-authored-by: Copilot App <[email protected]> Copilot-Session: 865fdec5-ee2f-4b62-9b82-873746691057
There was a problem hiding this comment.
Pull request overview
Adds MTP support for unpackaged WinUI test apps while preserving packaged MSIX activation.
Changes:
- Enables the PackagedApp launcher only for detected packaged layouts or explicit opt-in.
- Bounds and reports WinUI application startup failures.
- Adds acceptance coverage, an unpackaged sample, localization resources, and documentation.
Show a summary per file
| File | Description |
|---|---|
test/UnitTests/Microsoft.Testing.Extensions.UnitTests/PackagedAppTestHostLauncherTests.cs |
Tests launcher detection and overrides. |
test/IntegrationTests/MSTest.Acceptance.IntegrationTests/WinUITests.cs |
Marks the lightweight fixture unpackaged. |
test/IntegrationTests/MSTest.Acceptance.IntegrationTests/UnpackagedWinUITests.cs |
Adds unpackaged WinUI acceptance coverage. |
test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/PackagedAppDeploymentTests.cs |
Tests opt-in deployment and in-place execution. |
src/TestFramework/TestFramework.Extensions/Resources/xlf/FrameworkExtensionsMessages.zh-Hant.xlf |
Adds startup diagnostics localization entries. |
src/TestFramework/TestFramework.Extensions/Resources/xlf/FrameworkExtensionsMessages.zh-Hans.xlf |
Adds startup diagnostics localization entries. |
src/TestFramework/TestFramework.Extensions/Resources/xlf/FrameworkExtensionsMessages.tr.xlf |
Adds startup diagnostics localization entries. |
src/TestFramework/TestFramework.Extensions/Resources/xlf/FrameworkExtensionsMessages.ru.xlf |
Adds startup diagnostics localization entries. |
src/TestFramework/TestFramework.Extensions/Resources/xlf/FrameworkExtensionsMessages.pt-BR.xlf |
Adds startup diagnostics localization entries. |
src/TestFramework/TestFramework.Extensions/Resources/xlf/FrameworkExtensionsMessages.pl.xlf |
Adds startup diagnostics localization entries. |
src/TestFramework/TestFramework.Extensions/Resources/xlf/FrameworkExtensionsMessages.ko.xlf |
Adds startup diagnostics localization entries. |
src/TestFramework/TestFramework.Extensions/Resources/xlf/FrameworkExtensionsMessages.ja.xlf |
Adds startup diagnostics localization entries. |
src/TestFramework/TestFramework.Extensions/Resources/xlf/FrameworkExtensionsMessages.it.xlf |
Adds startup diagnostics localization entries. |
src/TestFramework/TestFramework.Extensions/Resources/xlf/FrameworkExtensionsMessages.fr.xlf |
Adds startup diagnostics localization entries. |
src/TestFramework/TestFramework.Extensions/Resources/xlf/FrameworkExtensionsMessages.es.xlf |
Adds startup diagnostics localization entries. |
src/TestFramework/TestFramework.Extensions/Resources/xlf/FrameworkExtensionsMessages.de.xlf |
Adds startup diagnostics localization entries. |
src/TestFramework/TestFramework.Extensions/Resources/xlf/FrameworkExtensionsMessages.cs.xlf |
Adds startup diagnostics localization entries. |
src/TestFramework/TestFramework.Extensions/Resources/FrameworkExtensionsMessages.resx |
Defines WinUI startup failure messages. |
src/TestFramework/TestFramework.Extensions/Attributes/WinUI_UITestMethodAttribute.cs |
Serializes and bounds WinUI initialization. |
src/Platform/Microsoft.Testing.Extensions.PackagedApp/TestingPlatformBuilderHook.cs |
Updates launcher registration documentation. |
src/Platform/Microsoft.Testing.Extensions.PackagedApp/Resources/xlf/ExtensionResources.zh-Hant.xlf |
Updates localized extension description. |
src/Platform/Microsoft.Testing.Extensions.PackagedApp/Resources/xlf/ExtensionResources.zh-Hans.xlf |
Updates localized extension description. |
src/Platform/Microsoft.Testing.Extensions.PackagedApp/Resources/xlf/ExtensionResources.tr.xlf |
Updates localized extension description. |
src/Platform/Microsoft.Testing.Extensions.PackagedApp/Resources/xlf/ExtensionResources.ru.xlf |
Updates localized extension description. |
src/Platform/Microsoft.Testing.Extensions.PackagedApp/Resources/xlf/ExtensionResources.pt-BR.xlf |
Updates localized extension description. |
src/Platform/Microsoft.Testing.Extensions.PackagedApp/Resources/xlf/ExtensionResources.pl.xlf |
Updates localized extension description. |
src/Platform/Microsoft.Testing.Extensions.PackagedApp/Resources/xlf/ExtensionResources.ko.xlf |
Updates localized extension description. |
src/Platform/Microsoft.Testing.Extensions.PackagedApp/Resources/xlf/ExtensionResources.ja.xlf |
Updates localized extension description. |
src/Platform/Microsoft.Testing.Extensions.PackagedApp/Resources/xlf/ExtensionResources.it.xlf |
Updates localized extension description. |
src/Platform/Microsoft.Testing.Extensions.PackagedApp/Resources/xlf/ExtensionResources.fr.xlf |
Updates localized extension description. |
src/Platform/Microsoft.Testing.Extensions.PackagedApp/Resources/xlf/ExtensionResources.es.xlf |
Updates localized extension description. |
src/Platform/Microsoft.Testing.Extensions.PackagedApp/Resources/xlf/ExtensionResources.de.xlf |
Updates localized extension description. |
src/Platform/Microsoft.Testing.Extensions.PackagedApp/Resources/xlf/ExtensionResources.cs.xlf |
Updates localized extension description. |
src/Platform/Microsoft.Testing.Extensions.PackagedApp/Resources/ExtensionResources.resx |
Documents conditional launcher behavior. |
src/Platform/Microsoft.Testing.Extensions.PackagedApp/PackagedAppTestHostLauncher.cs |
Implements layout-aware launcher enablement. |
src/Platform/Microsoft.Testing.Extensions.PackagedApp/PackagedAppExtensions.cs |
Documents automatic and override behavior. |
src/Platform/Microsoft.Testing.Extensions.PackagedApp/PACKAGE.md |
Updates package usage guidance. |
src/Platform/Microsoft.Testing.Extensions.PackagedApp/Microsoft.Testing.Extensions.PackagedApp.csproj |
Updates NuGet package description. |
src/Platform/Microsoft.Testing.Extensions.PackagedApp/InternalAPI/InternalAPI.Unshipped.txt |
Tracks new internal APIs. |
src/Platform/Microsoft.Testing.Extensions.PackagedApp/AppxManifestInfo.cs |
Bounds ancestor manifest discovery. |
samples/public/mstest-runner/MSTestRunnerWinUIUnpackaged/MSTestRunnerWinUIUnpackaged/UnitTests.cs |
Demonstrates plain and UI tests. |
samples/public/mstest-runner/MSTestRunnerWinUIUnpackaged/MSTestRunnerWinUIUnpackaged/UnitTestAppWindow.xaml.cs |
Defines the sample window. |
samples/public/mstest-runner/MSTestRunnerWinUIUnpackaged/MSTestRunnerWinUIUnpackaged/UnitTestAppWindow.xaml |
Defines the sample window UI. |
samples/public/mstest-runner/MSTestRunnerWinUIUnpackaged/MSTestRunnerWinUIUnpackaged/UnitTestApp.xaml.cs |
Self-hosts MTP in WinUI. |
samples/public/mstest-runner/MSTestRunnerWinUIUnpackaged/MSTestRunnerWinUIUnpackaged/UnitTestApp.xaml |
Defines sample application resources. |
samples/public/mstest-runner/MSTestRunnerWinUIUnpackaged/MSTestRunnerWinUIUnpackaged/Properties/launchSettings.json |
Adds unpackaged launch profile. |
samples/public/mstest-runner/MSTestRunnerWinUIUnpackaged/MSTestRunnerWinUIUnpackaged/MSTestRunnerWinUIUnpackaged.csproj |
Configures the unpackaged sample. |
samples/public/mstest-runner/MSTestRunnerWinUIUnpackaged/MSTestRunnerWinUIUnpackaged/app.manifest |
Declares desktop process compatibility. |
samples/public/mstest-runner/MSTestRunnerWinUIUnpackaged/MSTestRunnerWinUIUnpackaged.slnx |
Adds the sample solution. |
samples/public/mstest-runner/MSTestRunnerWinUI/MSTestRunnerWinUI/UnitTestApp.xaml.cs |
Propagates packaged sample exit codes. |
samples/public/mstest-runner/MSTestRunnerWinUI/MSTestRunnerWinUI/MSTestRunnerWinUI.csproj |
Clarifies packaged activation behavior. |
docs/winui-testing.md |
Adds comprehensive WinUI testing guidance. |
docs/README.md |
Links the new guide. |
docs/glossary.md |
Updates the PackagedApp definition. |
Review details
- Files reviewed: 54/54 changed files
- Comments generated: 2
- Review effort level: Medium
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
🤖 Automated content by GitHub Copilot. Generated by the Grade Tests on PR (on open / sync) workflow. · sonnet46 59.3 AIC · ⌖ 4.33 AIC · ⊞ 11.8K · ◷
The sample's first test asserted `0 == 0`, which no production change can ever break and which needed an MSTEST0032 suppression. Assert the property that actually defines this sample instead: the app runs with no MSIX package identity, so `Package.Current` throws. Co-authored-by: Copilot App <[email protected]> Copilot-Session: 865fdec5-ee2f-4b62-9b82-873746691057
There was a problem hiding this comment.
Review details
Comments suppressed due to low confidence (3)
src/Platform/Microsoft.Testing.Extensions.PackagedApp/AppxManifestInfo.cs:107
- The fixed two-level cap rejects valid packaged layouts whose
Application/@Executableis nested more deeply (the manifest schema permits arbitrary relative subdirectories up to its path-length limit). Inautomode that makesIsEnabledAsyncreturn false, so MTP falls back toProcess.Startfor an MSIX app that cannot be started that way. Please preserve support for all valid executable paths; if false-positive manifests are the concern, validate that a candidate manifest declares the current executable instead of assuming a maximum depth.
for (int depth = 0; directory is not null && depth <= MaxManifestSearchDepth; directory = directory.Parent, depth++)
docs/winui-testing.md:110
Directory.Packages.propscentralizes package versions but does not add a package reference, so a project cannot reference this extension “transitively” through that file. Remove this example or name a sharedDirectory.Build.propsthat actually contributes thePackageReference.
So an **unpackaged** WinUI app that references `Microsoft.Testing.Extensions.PackagedApp` (directly, or transitively through a shared `Directory.Packages.props`) pays nothing for it: no extra process, and no copy of the build output into a deployment directory.
docs/winui-testing.md:10
- This statement is incorrect for the packaged flavor: MTP still needs
Microsoft.Testing.Extensions.PackagedAppto register and AUMID-activate the app, as this guide explains later. Qualify the no-deployment/no-activation claim as unpackaged-only so readers do not omit the required packaged-app launcher.
This issue also appears on line 110 of the same file.
Both flavors are supported when you run on [Microsoft.Testing.Platform](https://learn.microsoft.com/dotnet/core/testing/unit-testing-platform-intro) (MTP), which you enable with `<EnableMSTestRunner>true</EnableMSTestRunner>`. Under MTP the WinUI app **is** the test host: it hosts the platform in-process, so no external test host provider has to deploy or activate anything.
- Files reviewed: 54/54 changed files
- Comments generated: 0 new
- Review effort level: Medium
There was a problem hiding this comment.
🤖 Automated content by GitHub Copilot. Generated by the Grade Tests on PR (on open / sync) workflow. · sonnet46 69.4 AIC · ⌖ 4.08 AIC · ⊞ 11.8K · ◷
The bounded upward search for AppxManifest.xml traded one problem for another: it stopped a stray manifest in a shared build root from misclassifying an unrelated test app, but it also misclassified a valid packaged layout whose Application/@eXecutable is nested deeper than the cap. In that case the launcher stayed disabled in auto mode, and even the explicit `always` opt-in could not recover because the launch path shared the same bounded lookup and treated the layout as loose. Replace the cap with attribution. The manifest sitting in the app's own directory is still accepted without parsing, which keeps the common case and its cost unchanged. An ancestor manifest is now accepted only when one of its applications declares an executable that resolves back to the app directory (or, on the launch path, to the requested executable), so a manifest that has nothing to do with this app no longer enables the launcher no matter where it sits. Malformed or unreadable ancestor manifests are ignored rather than failing enablement, and package-relative executable paths that escape the layout are rejected. Co-authored-by: Copilot App <[email protected]> Copilot-Session: 865fdec5-ee2f-4b62-9b82-873746691057
The unrecognized-mode test expected false against a loose layout, which is the same result the loose-layout baseline already produces, so a change that short-circuited any unknown mode straight to disabled would have gone unnoticed. Assert the packaged layout instead, which only returns true if the probe really ran, and keep the loose-layout case as its own test so both directions stay covered. Co-authored-by: Copilot App <[email protected]> Copilot-Session: 865fdec5-ee2f-4b62-9b82-873746691057
There was a problem hiding this comment.
Review details
Comments suppressed due to low confidence (2)
src/Platform/Microsoft.Testing.Extensions.PackagedApp/AppxManifestInfo.cs:117
- The PR description still says this search is bounded by
MaxManifestSearchDepth = 2, but the current implementation deliberately walks to the root and attributes ancestor manifests by executable path. Please update the description so reviewers and release notes reflect the implemented design and the resolution of the prior depth-limit feedback.
while (directory is not null)
src/Platform/Microsoft.Testing.Extensions.PackagedApp/AppxManifestInfo.cs:113
- The default launcher passes
AppContext.BaseDirectory, which has a trailing directory separator.Path.GetFullPathpreserves that separator, butPath.GetDirectoryName(applicationExecutablePath)at line 164 does not, so a valid ancestor manifest is never attributed to a deeply nested app during enablement. Normalize the ending separator here (and cover a trailing-separator input) so the production path behaves like the current tests' separator-free paths.
string fullStartDirectory = Path.GetFullPath(startDirectory);
- Files reviewed: 55/55 changed files
- Comments generated: 0 new
- Review effort level: Medium
There was a problem hiding this comment.
Review details
Comments suppressed due to low confidence (7)
docs/winui-testing.md:107
- The table currently implies that any ancestor
AppxManifest.xmlenables the launcher. The implementation deliberately rejects an ancestor unless anApplication/@Executableresolves to this app directory (and ignores malformed or unattributable manifests), so document that condition to avoid misleading users whose manifest omitsExecutable.
| Packaged layout (`AppxManifest.xml` found at or above the app directory) | yes | The layout is registered and activated by AUMID. |
samples/public/mstest-runner/MSTestRunnerWinUIUnpackaged/MSTestRunnerWinUIUnpackaged/app.manifest:13
- This blank line contains trailing spaces, which violates the repository-wide
trim_trailing_whitespace = truerule in.editorconfig:9.
docs/winui-testing.md:10 - This says neither flavor needs activation, but the packaged path documented below explicitly requires
Microsoft.Testing.Extensions.PackagedAppto register and activate the app by AUMID. Clarify that only unpackaged apps start directly; packaged apps still self-host MTP after the launcher activates them.
This issue also appears on line 107 of the same file.
Both flavors are supported when you run on [Microsoft.Testing.Platform](https://learn.microsoft.com/dotnet/core/testing/unit-testing-platform-intro) (MTP), which you enable with `<EnableMSTestRunner>true</EnableMSTestRunner>`. Under MTP the WinUI app **is** the test host: it hosts the platform in-process, so no external test host provider has to deploy or activate anything.
src/Platform/Microsoft.Testing.Extensions.PackagedApp/PACKAGE.md:20
- This table implies that any ancestor
AppxManifest.xmlenables the launcher, but the implementation only accepts an ancestor whoseApplication/@Executableresolves to the app directory. State that attribution requirement so package consumers are not told that ancestor manifests withoutExecutableare auto-detected.
| Packaged layout (`AppxManifest.xml` at or above the app directory) | yes |
src/Platform/Microsoft.Testing.Extensions.PackagedApp/AppxManifestInfo.cs:117
- The PR description still says the ancestor search is bounded by
MaxManifestSearchDepth = 2, but this implementation now walks to the root and filters candidates by executable attribution. Update the PR description so reviewers and release notes do not document a limit that no longer exists.
while (directory is not null)
samples/public/mstest-runner/MSTestRunnerWinUIUnpackaged/MSTestRunnerWinUIUnpackaged/app.manifest:7
- This new line has trailing whitespace, which violates the repository-wide
trim_trailing_whitespace = truerule in.editorconfig:9.
This issue also appears on line 13 of the same file.
<!-- The ID below informs the system that this application is compatible with OS features first introduced in Windows 10.
docs/glossary.md:378
- “At or above” is broader than the implemented auto-detection: an ancestor manifest is accepted only when an
Application/@Executableresolves to this app directory. Document that condition here as well, especially because ancestor manifests withoutExecutableare intentionally ignored.
An experimental MTP extension (`Microsoft.Testing.Extensions.PackagedApp`, `[Experimental("TPEXP")]`, ships as `1.0.0-alpha`) that enables testing packaged Windows apps (full-trust MSIX desktop, e.g. packaged WinUI) by registering the layout with the `PackageManager` and activating it by AUMID through the [ITestHostLauncher](#itesthostlauncher) extension point, rather than a plain `Process.Start`. Register via `builder.AddPackagedAppDeployment()`, or simply by referencing the package (its MSBuild props register the hook). The launcher only enables itself when the test application is a packaged layout — an `AppxManifest.xml` at or above the app directory — so referencing it from an **unpackaged** app does not force the test host controller process model or copy the build output; `TESTINGPLATFORM_PACKAGEDAPP_LAUNCHER` (`auto`/`always`/`never`) overrides that decision. Introduced in [PR #9454](https://github.com/microsoft/testfx/pull/9454); AUMID activation added in [PR #9970](https://github.com/microsoft/testfx/pull/9970). See also [ITestHostLauncher](#itesthostlauncher) and [docs/winui-testing.md](winui-testing.md).
- Files reviewed: 55/55 changed files
- Comments generated: 2
- Review effort level: Medium
The launcher passes AppContext.BaseDirectory, which ends with a directory separator, while Path.GetDirectoryName never returns one. Comparing the two unnormalized meant the equality check could not match, so a valid ancestor manifest was never attributed during enablement and a deeply nested packaged layout stayed unrecognized in production. The existing tests missed it because they build their paths with Path.Combine and so never carry a trailing separator. Normalize both sides of the comparison and add a regression test that passes a trailing separator the way the launcher does; that test fails without this change. Co-authored-by: Copilot App <[email protected]> Copilot-Session: 865fdec5-ee2f-4b62-9b82-873746691057
There was a problem hiding this comment.
Review details
Comments suppressed due to low confidence (2)
src/Platform/Microsoft.Testing.Extensions.PackagedApp/AppxManifestInfo.cs:169
- When the manifest declares a different executable in the same directory as the requested host, the exact-path overload still accepts it via this directory fallback.
LaunchTestHostAsyncthen treats the layout as packaged, and a single-application manifest is resolved without checking the filename, so the launcher can activate the wrong AUMID. Use directory matching only for the directory-only enablement probe; whenexecutablePathis supplied, require an exact resolved-path match.
if (executablePath is not null
&& string.Equals(applicationExecutablePath, executablePath, StringComparison.OrdinalIgnoreCase))
{
return true;
}
string? applicationDirectory = Path.GetDirectoryName(applicationExecutablePath);
if (applicationDirectory is not null
&& string.Equals(NormalizeDirectory(applicationDirectory), appDirectory, StringComparison.OrdinalIgnoreCase))
src/TestFramework/TestFramework.Extensions/Attributes/WinUI_UITestMethodAttribute.cs:275
- The new acceptance test exercises only the callback's managed-exception path (the application constructor throws). It does not execute this dead-thread fallback—the branch added for the native startup failure described by the PR—or the live-thread timeout below it, so regressions in the two mechanisms that make the fix robust would still pass CI. Add deterministic coverage by isolating/injecting the startup thread and timeout behavior, then test both “thread exits without completing initialization” and “thread remains alive without completing initialization.”
- Files reviewed: 55/55 changed files
- Comments generated: 0 new
- Review effort level: Medium
The launch path is handed the exact executable it must start, but the ancestor-manifest check also accepted any application that merely resolved into the same directory. A package declaring a different application beside the requested host therefore matched, and because ResolveApplication returns a lone application unconditionally, the launcher would have activated the wrong Application User Model ID. Require the full executable path to match whenever the caller supplies one. Enablement has no launch context and so still attributes on the app directory, which is the weakest signal that can work there. Co-authored-by: Copilot App <[email protected]> Copilot-Session: 865fdec5-ee2f-4b62-9b82-873746691057
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
🤖 Automated content by GitHub Copilot. Generated by the Grade Tests on PR (on open / sync) workflow. · sonnet46 80.5 AIC · ⌖ 4.31 AIC · ⊞ 11.7K · ◷
Three findings from review, all in the startup path added for issue #2784. The timeout said Application.Start "never invoked its initialization callback", but the wait is only completed after the callback constructs the application, so the timeout also fires when the callback was invoked and then blocked. Saying the callback never ran is false in that case and misdirects diagnosis, so say that initialization did not complete instead. The liveness and timeout guards are what keep a startup problem a test failure rather than a hung run, yet neither was covered: the acceptance case exercises the managed catch, and neither guard is reproducible on demand from a test host. Separate the wait decision from the thread it observes so both branches can be driven directly, and cover them. Verified by mutation: making each guard stop reporting fails exactly its own test. Also trim the trailing whitespace the sample manifest inherited from the project template, which the repository-wide .editorconfig rule forbids. Co-authored-by: Copilot App <[email protected]> Copilot-Session: 865fdec5-ee2f-4b62-9b82-873746691057
|
Acted on all four suppressed low-confidence findings from the latest review in c9a2277.
Validation: PlatformServices unit tests 975/975 on the WinUI TFM and 1039/1039 on net9.0; the two WinUI acceptance tests still pass against a real XAML application (33s), covering both the success path and the failure path through the extracted helper; sample still builds. Assertions use the resource strings rather than English fragments so they stay culture-independent. |
A non-null dispatcher only showed that the control has one, not that the test body was running on that thread, which is what the test name claims. Assert thread access as well. Co-authored-by: Copilot App <[email protected]> Copilot-Session: 865fdec5-ee2f-4b62-9b82-873746691057
There was a problem hiding this comment.
Review details
Comments suppressed due to low confidence (3)
src/TestFramework/TestFramework.Extensions/Attributes/WinUI_UITestMethodAttribute.cs:302
TestFramework.Extensions.csprojincludes the per-TFMInternalAPIfiles as analyzer inputs (lines 101-112), but this new internal member is absent fromInternalAPI/net8.0-windows10.0.18362.0/InternalAPI.Unshipped.txt. The WinUI build will therefore report RS0016. Add the generated signature forWaitForApplicationStartup<T>to that file.
src/Platform/Microsoft.Testing.Extensions.PackagedApp/AppxManifestInfo.cs:379- A syntactically valid manifest can still contain an invalid or overlong
Executablepath.Path.GetFullPaththen throws here, outside the parse exception handler inIsAncestorManifestForApp, so probing a malformed ancestor manifest can fail the entire run despite the documented behavior of ignoring it. Treat path-normalization failures as a non-match.
string fullManifestDirectory = Path.GetFullPath(manifestDirectory);
string[] pathSegments = packageRelativePath.Split(['\\', '/'], StringSplitOptions.RemoveEmptyEntries);
string resolvedPath = Path.GetFullPath(Path.Combine([fullManifestDirectory, .. pathSegments]));
string relativePath = Path.GetRelativePath(fullManifestDirectory, resolvedPath);
docs/winui-testing.md:71
- This recommended
async voidhosting pattern only closes the window and exits after a successful run. If builder creation, build, orRunAsyncthrows, control never reaches these lines and the WinUI message loop can keep the process alive. Match the sample implementation by putting shutdown infinally.
// The WinUI-generated entry point is 'void', so publish the exit code yourself.
Environment.ExitCode = await app.RunAsync();
_window.Close();
Exit();
- Files reviewed: 56/56 changed files
- Comments generated: 0 new
- Review effort level: Medium
There was a problem hiding this comment.
🤖 Automated content by GitHub Copilot. Generated by the Grade Tests on PR (on open / sync) workflow. · sonnet46 133.1 AIC · ⌖ 4.06 AIC · ⊞ 11.8K · ◷
The test checked only the exception type, so a message that stopped naming the requested and declared executables would have survived it - even though naming both is what makes the failure actionable, and the neighbouring ambiguity test already asserts its message. Co-authored-by: Copilot App <[email protected]> Copilot-Session: 865fdec5-ee2f-4b62-9b82-873746691057
A non-empty string only showed that the call returned something. Parsing it as a version shows the bootstrapper resolved an actual runtime, which is the point of covering a Windows App SDK WinRT type from a plain test method. Co-authored-by: Copilot App <[email protected]> Copilot-Session: 865fdec5-ee2f-4b62-9b82-873746691057
|
Both grading items are addressed.
Sample rebuilt and run: 3/3 pass, exit code 0. |
There was a problem hiding this comment.
Review details
Comments suppressed due to low confidence (2)
src/TestFramework/TestFramework.Extensions/Attributes/WinUI_UITestMethodAttribute.cs:283
- No test exercises the remembered-failure behavior: the acceptance asset has only one failing
[UITestMethod], and the unit tests call onlyWaitForApplicationStartup, so removing this assignment or the later replay branch would leave every current test passing. Add a second UI test to the failing-startup asset and verify it reportsWinUIApplicationInitializationAlreadyFailedwhile preserving the original constructor message.
src/Platform/Microsoft.Testing.Extensions.PackagedApp/AppxManifestInfo.cs:378 - The new package-relative path boundary is not covered by any regression test: the current tests exercise valid nested and mismatched paths, but none uses a rooted, drive-qualified, or
..-traversingExecutable. These checks prevent an ancestor manifest from being attributed outside its layout, so a regression could re-enable the wrong launcher/AUMID path unnoticed. Add cases throughFindManifestPathfor each rejected form and assert the ancestor manifest is ignored.
return relativePath == ".."
|| relativePath.StartsWith($"..{Path.DirectorySeparatorChar}", StringComparison.Ordinal)
|| relativePath.StartsWith($"..{Path.AltDirectorySeparatorChar}", StringComparison.Ordinal)
|| Path.IsPathRooted(relativePath)
? null
- Files reviewed: 56/56 changed files
- Comments generated: 0 new
- Review effort level: Medium
🧪 Test quality grade — PR #10330
This advisory comment was generated automatically. Grades are heuristic
|
Addresses the unpackaged half of #2784 for Microsoft.Testing.Platform (MTP). VSTest is explicitly out of scope — see "Scope" below.
Why
Two separate things stood between an unpackaged WinUI app and a working test run under MTP.
1. The PackagedApp launcher was always on.
PackagedAppTestHostLauncher.IsEnabledAsync()returnedOperatingSystem.IsWindows()unconditionally, andTestHostControllersManagersetsrequireProcessRestart = truewhenever any launcher is enabled. So merely referencingMicrosoft.Testing.Extensions.PackagedApp— directly, or transitively through a sharedDirectory.Packages.props— forced an unpackaged app onto the out-of-process controller model and copied its entire build output into%TEMP%\MTPPackagedAppDeployment\<guid>on every run. That is the right trade for a packaged (MSIX) app, which genuinely cannot be started in place, and pure overhead for an app that just needsProcess.Start.2.
UITestMethodAttributecould hang the whole run.InitializeApplicationhad an emptycatch { }, so a failure while bringing the application up left theTaskCompletionSourceincomplete andtsc.Task.Wait()blocked forever, with no diagnostic at all. That is exactly what an unpackaged app hits when the Windows App SDK runtime cannot be resolved (COMException/REGDB_E_CLASSNOTREG).What changed
The launcher now decides per layout
AppxManifest.xmlthat describes this app)TESTINGPLATFORM_PACKAGEDAPP_LAUNCHER=auto(default) /always/neveroverrides the probe. An env var rather than a CLI option, because enablement is decided before options are read and a CLI option would surface in--helpfor every consumer.How a manifest is attributed. The manifest sitting in the app's own directory is accepted without parsing, which keeps the common case and its cost unchanged. An ancestor manifest is walked up to without a depth limit, but is accepted only when one of its applications declares an executable that resolves back to the app directory — or to the requested executable on the launch path. That preserves arbitrarily deep, legal package-relative executable paths while still ensuring a stray
AppxManifest.xmlin a shared build root or CI staging directory cannot classify an unrelated console test app as packaged and hijack its run. Malformed or unreadable ancestor manifests are ignored rather than failing enablement, and package-relative paths that escape the layout (rooted, drive-qualified, or..-traversing) are rejected.The hang is fixed
Failures now propagate instead of being swallowed. That alone was not sufficient: thread dumps of a hung host showed the "UI Thread for Tests" was gone entirely — XAML tears the thread down for some native startup failures without ever raising a managed exception, so no
catchcan fire. The fix therefore also treats the UI thread dying as a failure, and bounds the wait with an overall timeout for the case whereApplication.Startblocks without invoking its callback. Additionally: startup is serialized (Application.Startcan only run once per process), the statics arevolatile, the reflection wrapper is unwrapped so the reported message is the real cause rather than "Exception has been thrown by the target of an invocation", and the failure is remembered so later[UITestMethod]s report the same root cause instead of a generic message.Samples and docs
samples/public/mstest-runner/MSTestRunnerWinUIUnpackaged—WindowsPackageType=None, noPackage.appxmanifest, no logo assets. This is what was asked for on the issue.Environment.ExitCode = await app.RunAsync(). The WinUI-generated entry point isvoid, so without this a test app always exits 0 and failing tests never fail the build. Verified: exit code is now 9 instead of 0 on a failing run.docs/winui-testing.md: packaged vs unpackaged, self-hosted vsWinUITestTargetwiring (usingWinUITestTargetin a self-hosted app starts a second application), how the Windows App SDK bootstrapper is initialized, and the known MrtCorePRI257/PRI263warning.Scope
VSTest is not addressed. Its
UwpTestHostRuntimeProviderunconditionally reads anAppxManifest.xmlfrom the build output and throwsFileNotFoundExceptionwhen there is none — that provider ships in Visual Studio, not in this repository. Under MTP the WinUI app is the test host, so no appx provider is involved.Verification
Microsoft.Testing.Extensions.UnitTestsTestFramework.UnitTestsBeyond the suites passing, the behaviour claims were proven directly rather than asserted:
PackagedAppDeployment_WithNonPackagedLayoutAndNoOptIn_RunsInPlaceasserts the app runs from its own output directory; the timing is the tell — 1.98s in place vs 8.5s for the deploy path.IsEnabledAsync_WithTrailingSeparatorOnAppDirectory_IsEnabledfails without the accompanying normalization fix.The new acceptance tests build real
Microsoft.WindowsAppSDKapps withdotnet build, so they run on every Windows CI leg rather than being skipped.Notes for reviewers
InternalAPI.Unshipped.txt. No CLI options added, so no--help/--infoexpectations changed (the 30 help/info acceptance tests confirm this)..resxand the.xlffiles regenerated with/t:UpdateXlf.PackagedAppDeploymentTestsgained[DoNotParallelize]: it now has two methods sharing one generated asset, and one of them deploys that directory while the other writes into it.MrtCorePRI warning cannot be silenced withNoWarnorMSBuildWarningsAsMessages(thePRI…code is in the message text, not the MSBuild warning code), so the asset build opts out of-warnaserror; this is documented for users too.