Hi,
I've tried several methods of being able to write unit tests with MAUI and the Maps SDK but none have worked. I tried the approach described here:
https://www.youtube.com/watch?v=C9vIDLQwc7M
and here: https://cedricgabrang.medium.com/adding-xunit-test-to-your-net-maui-project-ee36c00a8542
This is with a brand new MSTest project template from VS. csproj looks like this:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Esri.ArcGISRuntime" Version="200.2.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.1" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.10" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.10" />
<PackageReference Include="coverlet.collector" Version="3.2.0" />
</ItemGroup>
</Project>
This works fine without Maps SDK, but as soon as I add the Esri.ArcGISRuntime nuget package reference, I get this:
Severity Code Description Project File Line Suppression State
Error The 'Esri.ArcGISRuntime' nuget package cannot be used to target 'net7.0' for output type 'Exe'. Only platform-agnostic class libraries or Windows, iOS and Android platforms are supported. TestProject1 C:\Users\JSIEMENS\.nuget\packages\esri.arcgisruntime\200.2.0\buildTransitive\net6.0\Esri.ArcGISRuntime.targets 5
So then I saw a suggestion to set the TargetFramework to "net7.0-windows10.0.19041.0", so I try that, and it works fine without Maui, but once I add <UseMaui>true</UseMaui>, then I get:
Architecture: x64
Framework: 'Microsoft.Maui.Core', version '**FromWorkload**' (x64)
.NET location: C:\Program Files\dotnet\
No frameworks were found.
Learn about framework resolution:
https://aka.ms/dotnet/app-launch-failed
To install missing framework, download:
https://aka.ms/dotnet-core-applaunch?framework=Microsoft.Maui.Core&framework_version=**FromWorkload*...
. Please check the diagnostic logs for more information.
It feels the same as this issue:
https://github.com/dotnet/maui/issues/17914
And: https://github.com/dotnet/maui/issues/11575
Here's the csproj again.
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0-windows10.0.19041.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<UseMaui>true</UseMaui>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.1" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.10" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.10" />
<PackageReference Include="coverlet.collector" Version="3.2.0" />
</ItemGroup>
</Project>
So at this point in time, it feels like there is no way to run unit tests against a project that uses both MAUI and the ArcGIS Maps SDK. What am I missing? Is there a way to get tests to work?
Formerly with Xamarin Forms and UWP, there was a UWP test project template (which was horrifically slow to run tests with), but that doesn't seem to be a thing anymore with WinUI3.