Running Tests on iOS
- PDF for offline use
- Related Articles:
Let us know how you feel about this
last updated: 2016-10
If you have an iOS 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 submit the test run to Test Cloud.
- Programmatically Declaring the Device – Using the UITest API, a test can explicitly identify a device to run the tests on.
Each of these topics will be discussed in more detail below.
Running Tests with the IDE
To run the the tests on a local device, first set the startup project to the iOS project. Next, change the build configuration to Debug > iOS Device:
The open the Unit Tests pad in Xamarin Studio by selecting View > Pads > Unit Tests.
The first time you want to run test, you will have to Right click on the project in the test pad, and select Run Tests.
The test will run on the selected device. When the tests have completed, you will be able to see the results in the Test Results pad:
Programmatically Declaring the Device
If you wish to run your tests at the command line using a script or via CI, then it is necessary to install the IPA on the device. Also, it may be necessary programmatically set the following two pieces of information in your UITest:
- Build Identifier of the installed application – You can find this in Project Options > Build > iOS Application as the Bundle Identifier:
- Device Identifier – This is a unique string value that identifies each iOS device and simulator attached to a Mac. It is only required if there is more than one simulator or device. Please see the guide Selecting an iOS Simulator for Local Xamarin.UITests for details on how to obtain the device identifier.
Setting the device identifier is not always necessary. If there are no iOS simulators running but a single iOS device is connected, then UITest will run the tests on the device without have to declare the device identifier. If there are multiple simulators running or more than one device attached, you must specify the device identifier.
The following code snippet demonstrates how to provide these two values to the
IApp app = ConfigureApp.iOS .EnableLocalScreenshots() .DeviceIdentifier("f8c67472f88efb1985c2f5e73698d6bb36988f5d") .InstalledApp("com.xamarin.calabash.example.creditcardvalidation") .StartApp();