Writing Unit Tests for Your .NET MAUI App
Mark starts from the familiar ground of testing the logic in your app and skipping the views. He prefers xUnit, though he notes that NUnit and MSTest are equally solid, and he rewrites the Hello World app to use a ViewModel built with the Community Toolkit MVVM library so there’s something to test.
The test itself follows Arrange/Act/Assert: create the ViewModel, execute the counter command and check the count. Adding a project reference from the test project to the MAUI project is where things get interesting. If your logic lives in the app project, the test project won’t compile until you add a condition to OutputType in the app’s .csproj, so that Exe only applies when the target framework isn’t the net7.0 one. He adds how to adjust the condition for other .NET versions.
If you’ve set up unit tests before, the post even suggests skipping straight to the TL;DR section for the fix. The full example is on GitHub.