Unit Testing an Android Class Library

jenkins957jenkins957 GBMember

Hi,

Does anyone know the correct way to create a Unit Test project for testing a Class Library (Android)?
Ideally I want pure unit tests that do not require the emulator. I will be mocking the components that use Android specific code.

Do I have to use a Unit Test App (Android) project?
or can I use a standard C# Unit Test project?

When using a standard Unit Test project it complains about references to Mono.Android - Adding this in then results in the following...
System.DllNotFoundException: Unable to load DLL 'jvm.dll': The specified module could not be found.

Using the Unit Test App seems to require the emulator to run the tests, which I want to avoid.

Is there any solution in the middle?

Thanks

Posts

  • Any update on this? It would be great to have an example of how to do this.

  • AleksanderisAleksanderis LTMember
    edited December 2016

    Still no updates? Would be good to hear any more comments about it!
    I find existing suggested unit-testing practice with Xamarin as quite not helpful from pure TDD perspective (response is just too long).
    I don't get why I need to include Android stuff (like Resources/Activity) into my Test project and run it on emulator to test just some Class libraries.

    It feels that it should be possible to do tests separately from Android, but the actual problem it seems stands around Mono/Xamarin/Java Interop references. There is some low-level magic happens around how everything is wired-up at the end. And is not very clear for me as for .NET developer, just starting with Xamarin. ;)

  • ErinMartellErinMartell USMember

    Any updates on this? I have the same question...

  • GeoffAGeoffA ✭✭ USMember ✭✭

    Faced the same issue before, I don't think that it can be easily done. Your best bet it to make the business logic as separated from the Android specific code as possible and unit test that, mocking what you can. Then just bolt it to the Android specific code and write a small test cross platform (UI Test App) against an emulator or device. You could run/test the app in Test Cloud and integrate this to your CI solution.

Sign In or Register to comment.