Unit Testing Maui with Esri 100.14.0.Preview2 with Xunit

2480
10
06-30-2022 02:38 PM
MeridithSpellerberg
New Contributor

Hi - we are updating an older Xamarin application (UWP, iOS) to Maui (Win UI/iOS) with the latest preview of ESRI. Everything converted fine with the exception of our unit tests. When we create a basic Maui application we are able to add Xunit tests without problem, but when we add in the latest ESRI packages we get the error 

Project '..{our app name}.csproj' targets 'net6.0;net6.0-windows10.0.194941.0.' it cannot be referenced by a project that targets '.NetCoreApp,version=v6.0'.

NU1201 Project {our app name} is not compatible with net6.0 (.NETCoreApp, Version=v6.0).  

 

Has anyone had any luck with this? 

Tags (1)
0 Kudos
10 Replies
dotMorten_esri
Esri Notable Contributor

What you're really hitting here is a limitation of Microsoft's test framework. To fully run Maui, you need to run as a packaged app on Windows, as a Catalyst app on Mac, and as app packages on iOS and Android. Today TestExplorer does not support running test in this context, because it only supports using VSTest to call into a DLL and not talking to a separate application process (well it does for UWP... see below). The test project you were using and referring to in the window isn't running in the context of how the application will ultimately run (as a packaged / sandboxed app), but merely as a simple console app that the Test Explorer talks to.

However to fully run MAUI and ArcGIS Runtime, you will need to run in the context of an application. We cannot run on Mac as a "normal" Mac console app - catalyst is required, and catalyst requires running as an application (sorry I forgot about this detail in my earlier reply). To put it another way: We don't support running on MacOS - we support running on MacCatalyst, and Microsoft's test runner does not today support that.

To run a unit test in the context of an application, you need a test runner application. I know Microsoft has their own they are using internally, and we've ported MSTest to iOS, Android and Catalyst to get around the same limitation (search for MSTestX on NuGet). I think XUnit has something as well here: https://github.com/shinyorg/xunit-maui 


TestExplorer has the capability to do this (this is how you run tests on UWP, as well as how we used to run unit tests on Windows Phone), but they haven't put in the work to support anything but UWP at this time.

0 Kudos