Microsoft has updated MSTest to version 4.5 and Microsoft.Testing.Platform to version 2.5, bringing a unified UI testing model to Universal Windows Platform (UWP) and WinUI 3 applications. The updates allow test initialization, asynchronous code execution, and cleanup routines to execute directly on an application's native UI thread rather than a general single-threaded apartment thread.
Unified Sidecar Execution Architecture
MSTest.Sdk coordinates test execution across unpackaged WinUI 3, packaged applications, modern UWP, classic UWP, and AppContainer hosts. Instead of depending on legacy components like vstest.console, Microsoft.NET.Test.Sdk, or UwpTestHostRuntimeProvider, MSTest.Sdk uses a full-trust sidecar controller. For unpackaged WinUI 3 projects, the tool starts the apphost directly. For packaged software, the sidecar controller registers the output layout and activates the host app via its Application User Model ID using Microsoft.Testing.Extensions.PackagedApp, handling command-line arguments, test cancellation, retry attempts, and reporting.
UI Dispatcher Integration
The framework utilizes the UITestMethod attribute to grant UI thread access throughout test setup, test logic, and cleanup. In WinUI 3 test applications, developers assign the main window's DispatcherQueue inside the OnLaunched entry point before passing process arguments to the generated Microsoft.Testing.Platform execution helper. This approach replaces STATestMethod workflows, which established single-threaded apartment threads without constructing a native WinUI dispatcher.
Environment Requirements and CI Execution
Executing packaged or AppContainer test hosts requires specific system setup. Registering unsigned build output layouts depends on Developer Mode or an active sideloading policy on development workstations and continuous integration agents. AppContainer tests and UWP builds run through non-elevated Developer PowerShell environments using the InvokeTestingPlatform MSBuild target, whereas unpackaged WinUI 3 projects can also execute directly via standard dotnet run or dotnet test commands.
AI-generated editorial illustration; not a documentary photograph.
Source: UWP and WinUI 3 apps: UI testing with MSTest

Leave a Reply