Skip to main content

Add Unit Tests to a .NET MAUI Application

You can create unit test for .NET MAUI applications that contain DevExpress .NET MAUI Controls in any of the following ways:

  • Move ViewModels, Services, and other modules into a separate assembly and then test this assembly.
  • Add the net8.0 to target versions of your project and then test this assembly. To do this, perform the following steps:

    1. Add the net8.0 to target frameworks in your app’s project file:

      <Project Sdk="Microsoft.NET.Sdk">
          <PropertyGroup>
              <TargetFrameworks>net8.0;net8.0-android;net8.0-ios</TargetFrameworks>
              <OutputType Condition="'$(TargetFramework)' != 'net8.0'">Exe</OutputType>
              <!-- ... -->
          </PropertyGroup>
          <!-- ... -->
      </Project>
      
    2. Build your project for the net8.0 framework.

    3. Create a project and add your unit tests.
    4. Reference your .NET MAUI application in the unit test’s project:

      <Project Sdk="Microsoft.NET.Sdk">
          <PropertyGroup>
              <TargetFramework>net8.0</TargetFramework>
              <!-- ... -->
          </PropertyGroup>
          <ItemGroup>
              <PackageReference Include="xunit" Version="2.6.4" />
              <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
              <PackageReference Include="xunit.runner.visualstudio" Version="2.5.6">
                  <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
                  <PrivateAssets>all</PrivateAssets>
              </PackageReference>
          </ItemGroup>
          <ItemGroup>
              <ProjectReference Include="..\DXMauiApp\DXMauiApp.csproj" />
          </ItemGroup>
      </Project>