How to run Xamarin UI tests on Android emulator? Always I run my test on real devices, but for CI I need tests on emulator, but I don't know how and google didn't give me a specific answer
public class AppInitializer
{
private const string ApkPath = @"..\..\..\mob\mob.Droid\bin\Release\myApp.apk";
private const string AppPath = "mob.iOS.app";
public static IApp StartApp(Platform platform)
{
if (platform == Platform.Android)
{
return ConfigureApp
.Android
.EnableLocalScreenshots()
.ApkFile(ApkPath)
.StartApp();
}
return ConfigureApp
.iOS
.EnableLocalScreenshots()
.StartApp();
}
}
To run the test on the application we have to simply build the Xamarin. UI test project and then the project. This will simply run all the test cases present inside the test class or if we want to run the specific test case then we have to select that particular test case and run it.
Develop the feature in the Android or iOS application. Write the tests and run them locally to verify functionality. Create a new Test Run in App Center Test, or use an existing Test Run. Compile the IPA or APK and then upload it along with the tests to App Center Test.
Best way to write Unit TestThe unit test should be independent. Code coverage of testing code should be above 85%. The unit test should be simple as there is no confusion of correctness of unit test code. Execution of unit test should be fast and generate an accurate result.
In the documentation and as @tequilaslammer mentions briefly:
Unlike testing on iOS, Xamarin.UITest will not automatically start the Android Emulator. It is necessary to have an Android emulator running or an Android device already connected. If there is more than one device or emulator connected, it will be necessary to provide the serial ID of the device/emulator that should be used to run the test.
Source: https://developer.xamarin.com/guides/testcloud/uitest/intro-to-uitest/#Initializing_AndroidApp
I highly recommend that you read through the complete documentation on this topic as there are a few "gotchas" that will need to be considered for your situation:
https://developer.xamarin.com/guides/testcloud/uitest/intro-to-uitest/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With