Running Tests on Android
- PDF for offline use:
Let us know how you feel about this.
last updated: 2016-12
If you have an Android device connected to your computer and it is properly configured, then Xamarin.UITest will attempt to deploy the application to the device and run the tests on it.
There are two ways to run tests on a local device:
- Through the IDE – Both Xamarin Studio and Visual Studio can submit the test run to Test Cloud.
- Programmatically Declaring the Device – Using the UITest API, a test can explicitly identify a device that it should be run on.
Each of these topics will be discussed in more detail below.
The Android device must be unlocked before Xamarin Studio can run the tests on the device.
Running Tests with the IDE
First set the Android project to be the startup project for the solution.
Next, open the Unit Test pad in Xamarin Studio by selecting View > Pads > Unit Tests. The tree view has a node called Test Apps:
Expand the test project in the Unit Tests pad, and select Run Test for the UITest project:
Once the tests have run, you can see the results in the Unit Tests pad and the Test Results pad:
Before trying to run the tests, ensure that you have build the APK or the IPA.
To run test on a local device, open the Test Explorer by selecting Test > Windows > Test Explorer.
Next, ensure that your Android device is connected to your computer, and then change the build target to Release and select the device that you want to run the tests on:
From here, you can run the unit tests from the Test Explorer.
Programmatically Declaring the Device
If there is only one device attached to the computer, and no running simulators, then UITest will automatically run the tests on the device.
If you have more than one device connected or an emulator running, then you must provide the serial identifier of the device that UITest should run the tests on. You can obtain a list of the devices and emulators using the Android Debug Bridge, as shown in the following snippet:
$ adb devices List of devices attached 0756edf000620ace device
The following snippet shows how to set the serial id for the
IApp instance used in the test:
IApp app = ConfigureApp.Android .DeviceSerial("0756edf000620ace") .ApkFile(PathToAPK) .StartApp();