Back to results for “Debugging”
.NET MAUI › Testing & Debugging

How do you unit test a MAUI app's logic?

Beginner

Answer

Put testable logic in view models and services (plain .NET classes), then test them with xUnit/NUnit/MSTest in a separate class-library targeting a plain TFM (e.g., net8.0). Because MVVM keeps logic out of the UI, you can instantiate view models, inject fakes, and assert on properties and commands without a device.
[Fact]
public async Task Login_SetsIsBusy_False_After_Complete()
{
    var vm = new LoginViewModel(new FakeAuth());
    await vm.LoginCommand.ExecuteAsync(null);
    Assert.False(vm.IsBusy);
}
Real-world example A team runs hundreds of view-model tests in CI in seconds, with no emulator required.

Common follow-ups: Why keep logic out of code-behind? | What TFM does the test project use?