Forum Xamarin.Android

Run Nunit tests for Android in console

VedaviBalajiVedaviBalaji INMember
edited March 2017 in Xamarin.Android

I have created a Nunit test for Android in Xamarin studio for Mac. This is how I created it : Solution -> Add Project -> Android : Unit Test App -> TestDroid.

A project with NunitLite reference, TestSample.cs, and no ManifestFile was created. It runs perfectly in android phone. But when I build the project and tried to run the .dll in console using this command :

/Library/Frameworks/Mono.framework/Versions/Current/bin/nunit-console4 TestApplication/TestDroid/bin/Debug/TestDroid.dll

I get the error :
Could not load file or assembly 'TestDroid, Version=, Culture=neutral, PublicKeyToken=null' or one of its dependencies.

Also, I tried removing the reference and added Nunit Nuget package, I still get the same error and my test classes does not appear Xamarin studio test runner pad (Unit test pad). - says Load failed.

I just want to know if at all it is possible to run the android unit test in console and not as an app? And why doesn't my unit test classes appear in the Unit test pad?

Note : I have tried a similar thing using the iOS exe file using this command :

/Library/Frameworks/Mono.framework/Versions/Current/bin/nunit-console4 TestApplication/TestiOS/bin/iPhoneSimulator/

and it works as expected.


  • mattwardmattward GBMember Xamurai

    The Unit Test App for Android needs to be run with an Android emulator or actual device. It runs an activity which hosts the tests. So you cannot run it from the command line.

    To use the Unit Tests window built into Xamarin Studio, or from the command line, you would need to be testing a supported project type, such as a portable class library (PCL) project. In this case you would have a normal .NET Framework project that uses NUnit and references the PCL project.

    Another alternative would be to create a UITest project. This runs the tests in the Android emulator but can be run from the command line with NUnit.

Sign In or Register to comment.