Skip to main content

MSTest lifecycle integration for Windows desktop UI Automation tests. MSTest is Microsoft supported Test Framework.

Total Downloads
237
237
Published
Oct 27, 2026
6d ago

Get Started

dotnet add package MSTest.Windows.UIAutomation --version 4.5.2
ProductVersions
.NET
net8.0-windows7.0net9.0-windows7.0

README

MSTest.Windows.UIAutomation

MSTest.Windows.UIAutomation integrates MSTest lifecycle management with the built-in Windows UI Automation API.

It launches a full-trust desktop application, discovers a window as an AutomationElement, and stops the application after each test.

This preview targets unpackaged Win32, WinForms, and WPF applications running in an interactive Windows session. It does not provide packaged MSIX/UWP/WinUI activation, elevated-process automation, a headless desktop, locators, automatic waits, screenshots, or a multi-window object model.

Getting started

Enable the feature when using MSTest.Sdk:

<Project Sdk="MSTest.Sdk/4.5.0">
  <PropertyGroup>
    <TargetFramework>net8.0-windows</TargetFramework>
    <EnableWindowsUIAutomation>true</EnableWindowsUIAutomation>
  </PropertyGroup>
</Project>

Then derive your test class from WindowTest:

using System.Diagnostics;
using Microsoft.VisualStudio.TestTools.UnitTesting.Windows.UIAutomation;
using Microsoft.VisualStudio.TestTools.UnitTesting;

[STATestClass]
public sealed class MyAppTests : WindowTest
{
    protected override ProcessStartInfo CreateProcessStartInfo()
        => new(@"C:\MyApp\MyApp.exe");

    [TestMethod]
    public void MainWindowIsAvailable()
        => Assert.IsNotNull(MainWindow);
}

ApplicationTest provides process lifecycle management. WindowTest additionally waits for a window and exposes it through MainWindow. Override FindWindow for launcher processes, splash screens, or applications whose desired window is not Process.MainWindowHandle. If the selected window belongs to a process other than the process created by CreateProcessStartInfo, also override StopApplication to track and stop that process.

Concrete test classes must declare [STATestClass]; MSTest test-class attributes are not inherited.

The package uses the UIA2 System.Windows.Automation API. Additional UI automation libraries can be layered on top when richer element interaction is needed.

Without MSTest.Sdk

Reference MSTest.Windows.UIAutomation together with MSTest.TestFramework, MSTest.TestAdapter, and Microsoft.NET.Test.Sdk, then import Microsoft.VisualStudio.TestTools.UnitTesting.Windows.UIAutomation. The package version should match the MSTest framework and adapter versions.

When restoring or building the Windows-targeted project on Linux or macOS, set:

<EnableWindowsTargeting Condition=" '$(EnableWindowsTargeting)' == '' and '$(OS)' != 'Windows_NT' ">true</EnableWindowsTargeting>

Downloads by Version

Similar & Alternative Packages

Hand-picked matching NuGet libraries based on tags & ecosystem

Depended On By

Find packages that declare this package as a dependency. NuGet does not provide a reverse-dependency endpoint, so candidates are checked on demand.

Adoption Assessment

A verified publisher signal is available. Assess fit from the package's supported frameworks, license and dependency graph rather than popularity alone.

Compatibility metadata lists 2 target frameworks; confirm the exact target used by your application.

Related Guides & Workflows

Learn how to evaluate, integrate, or audit this package in your .NET project.