Home > database >  Unit test Xamarin Android project business logic
Unit test Xamarin Android project business logic

Time:10-13

I have a problem with Unit testing a Xamarin Android project.

My setup:

  • Shared Xamarin project
  • ClientX.Android
  • ClientX.iOS
  • Native.Android
  • Native.iOS

Native.Android contains no resources, no MainActivity and no Androidmanifest. It's just shared Mono.Android code and normal business logic for it.

I have an Xunit testing project with which I have been able to test the Shared Xamarin project.

I need to test some business logic that is contained inside Native.Android but I get an error (which does make sense to me):

Severity Code Description Project File Line Suppression State Error NU1201 Project Client.XXXX.NativeDroid is not compatible with netcoreapp3.1 (.NETCoreApp,Version=v3.1). Project Client.XXX.NativeDroid supports: monoandroid12.0 (MonoAndroid,Version=v12.0) XXX.UnitTests

I can't find how I should go about Unit tests inside a Xamarin Android project that is not view/UI related.

CodePudding user response:

I managed to find the answer.

Using this project: https://github.com/xunit/devices.xunit You can run Platform specific (iOS/Android) unit tests (not UI tests). See the "Integration" folder in that project for examples of projects. Update the dependencies, add the references to the other projects you need inside Visual Studio and it should work for your own Xamarin 5 project.

  • Related