Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to test shared code in Xamarin

I have a Xamarin solution with 3 projects:

  • Android
  • iOS
  • Shared

Shared is a shared project containing all the shared logic. E.g. database access using sqlite-net, rest calls using restsharp.

I want to test the code in Shared.

I created an NUnit Library Project and created a test in it.

Now the project cannot compile because it can't find dll's that the Shared project needs.

These dll's are not referenced directly by Shared. E.g., the Android project references the android version of the sqlitenet.dll.

How can I test the shared code?

like image 860
daramasala Avatar asked Aug 26 '26 16:08

daramasala


1 Answers

The shared project is just a container for linked files, or put another way the shared project does not directly have any references but get whatever references the projects that reference it have.

If you have an iOS and Android project that reference a shared project, to properly unit test all possible code paths you would need android and iOS versions of the unit testing projects that reference the shared project and also reference anything the shared project needs, such as SqLite and define any needed compilation constants.

If the code is partially the same between the iOS and Android unit tests (and it likely is) you can use a shared project to share that code too.

like image 63
Kevin Ford Avatar answered Aug 28 '26 07:08

Kevin Ford



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!