Running Tests in the IDE
- PDF for offline use:
Let us know how you feel about this.
0/250
last updated: 2016-10
This guide will discuss how to run UITests in either Xamarin Studio or Visual Studio.
Overview
This guide will discuss how to run Xamarin.UITests in Xamarin Studio or Visual Studio and view the test results.
Requirements
This guide assumes that you already have a solution for a mobile application that includes a UITest project.
- NUnit 2.6.x – Xamarin.UITest is not compatible with NUnit 3.x.
- Android SDK – Only if testing Android apps.
- Java Developers Kit – Only if testing Android apps.
- Xcode Command Line Tools – Only for testing iOS apps.
Xamarin.UITest does not support Windows Phone.
- NUnit 2.6.x – Xamarin.UITest is not compatible with NUnit 3.x.
- A Test Runner for Visual Studio – A 3rd party test runner, such as the NUnit Test Adapter or Resharper from Jetbrains, is required for Visual Studio to be able to run the NUnit tests.
- Android SDK – Only if testing Android apps. Windows requires that the
ANDROID_HOMEenvironment variable is set with the path to the Android SDK. - Java Developers Kit – Only if testing Android apps.
It is not possible to run UITests for iOS apps in Visual Studio or on Windows.
Xamarin.UITest does not support Windows Phone.
Running Tests in the IDE
To run all of the unit tests in the solution, select Run > Run Unit Tests from the Xamarin Studio menu. This will cause the Unit Tests pad to appear. The Test Apps leaf of the tree shows the Xamarin.Android and the Xamarin.iOS projects along with the target of the test run:
The target identifies the physical device/Android emulator/iOS simulator that the tests will be run on. To run the tests, click the Run All button in the Unit Tests pad. Xamarin Studio will perform the following steps:
- Compile the solution.
- If necessary, start up the emulator or simulator identified by the test target.
- Deploy the app to the target and start the application.
- Run all the UITests.
- Collect the results and display them in either the Unit Test pad or the Test Results pad:
To run a individual test or tests for a specific device, right click on the test and select Run Test from the context:
Changing the Target
It is possible to select a different target to run the UITests on. Right click on the App Project under Test Apps in the Unit Tests pad, and select the new target for the test:
In Visual Studio, it is possible for the NUnit Test Adapter to deploy and run the UITests on an Android device and to display the test results inside the IDE.
- First, select the UITest project and add a reference to the Xamarin.Android project that is to be tested:
- Next, open the Test Explorer; by select Test > Windows > Test Explorer from the Visual Studio menu:
- Now it is necessary to specify the select the target device that the tests will run on. This can be any Android emulator or physical device:
- Finally, run the tests by selecting Test > Run > All Tests from the Visual Studio menu, or pressing Ctrl+R,A. This will cause Visual Studio deploy the APK, run the UITests, and display the output of the tests in the Test Explorer:
By doing this, UITest will automatically configure the IApp instance in the UITests to use the APK from the Xamarin.Android project that is referenced.
To run a individual test or tests for a specific device, right click on the test and select Run Selected Tests from the context menu:
When running tests locally, ensure that the compiled application targets a CPU architecture that is appropriate for the device running the tests:
| Target | Architecture |
|---|---|
| iOS Simulator | x86 |
| iOS device | x86_64 |
| Android Device | Typically armeabi-v7a |
| Google Emulator | Depends on the Android Virtual Device |
Running Android 6.0 Applications from the IDE
When the IDE installs an Android 6.0 app for the first time, it does not grant all permissions required by the application. The workaround for this is to use UITest to install and start the application:
ConfigureApp.Android.Debug().ApkFile(apkpath).StartApp ()
Do use ApkFile() and do not use PreferIdeSettings(). This will force UITest to install instead of the IDE.
Let us know how you feel about this.
0/250
Xamarin Workbook
If it's not already installed, install the Xamarin Workbooks app first. The workbook file should download automatically, but if it doesn't, just click to start the workbook download manually.