MAUIverse MAUIverse

.NET MAUI Device Runner Unit Tests

Some code only does its job on a platform, such as a library that calls into a native SDK, and a plain unit test project can’t exercise it. For those cases, Mark shows how to run xUnit tests inside a .NET MAUI app on a device or emulator.

His sample moves the Hello World counter logic into a ViewModel (using the Community Toolkit MVVM library) that lives in a class library. The test project is a new .NET MAUI app with the default pages removed, Shiny.Xunit.Runners.Maui from Allan Ritchie installed, and a short MauiProgram that configures the tests and calls UseVisualRunner(). You then launch the app and tap a button to run the tests.

He’s candid about the trade-offs. Device runs are slower because you wait for the emulator and tap to start, so he suggests keeping them for code that needs a device SDK, or for checking that code runs on a specific test device. The sample is on GitHub.

View Source →

← Back to Community Feed

}