Integrating Device Farm with XCTest for iOS
With Device Farm, you can use the XCTest framework to test your app on real devices. For more information about
XCTest, see Testing Basics
To run a test, you create the packages for your test run, and you upload these packages to Device Farm.
For more information about testing in Device Farm, see Test frameworks and built-in tests in AWS Device Farm.
Create the packages for your XCTest run
To test your app by using the XCTest framework, Device Farm requires the following:
-
Your app package as a
.ipa
file. -
Your XCTest package as a
.zip
file.
You create these packages by using the build output that Xcode generates. Complete the following steps to create the packages so that you can upload them to Device Farm.
To generate the build output for your app
-
Open your app project in Xcode.
-
In the scheme dropdown menu in the Xcode toolbar, choose Generic iOS Device as the destination.
-
In the Product menu, choose Build For, and then choose Testing.
To create the app package
-
In the project navigator in Xcode, under Products, open the contextual menu for the file named
. Then, choose Show in Finder. Finder opens a folder namedapp-project-name
.appDebug-iphoneos
, which contains the output that Xcode generated for your test build. This folder includes your.app
file. -
In Finder, create a new folder, and name it
Payload
. -
Copy the
file, and paste it in theapp-project-name
.appPayload
folder. -
Open the contextual menu for the
Payload
folder and choose Compress "Payload". A file namedPayload.zip
is created. -
Change the file name and extension of
Payload.zip
to
.app-project-name
.ipaIn a later step, you provide this file to Device Farm. To make the file easier to find, you might want to move it to another location, such as your desktop.
-
Optionally, you can delete the
Payload
folder and the.app
file in it.
To create the XCTest package
-
In Finder, in the
Debug-iphoneos
directory, open the contextual menu for the
file. Then, choose Show Package Contents.app-project-name
.app -
In the package contents, open the
Plugins
folder. This folder contains a file named
.app-project-name
.xctest -
Open the contextual menu for this file and choose Compress "
". A file namedapp-project-name
.xctest
is created.app-project-name
.xctest.zipIn a later step, you provide this file to Device Farm. To make the file easier to find, you might want to move it to another location, such as your desktop.
Upload the packages for your XCTest run to Device Farm
Use the Device Farm console to upload the packages for your test.
Sign in to the Device Farm console at https://console.aws.amazon.com/devicefarm
. -
If you don't have a project already, create one. For the steps to create a project, see Creating a project in AWS Device Farm.
Otherwise, on the Device Farm navigation panel, choose Mobile Device Testing, then choose Projects.
-
Choose the project that you want to use to run the test.
-
Choose Create a new run.
-
On the Choose application page, choose Mobile App.
-
Select Choose File.
-
Browse to the
.ipa
file for your app and upload it.Note
Your
.ipa
package must be built for testing. -
After the upload completes, choose Next.
-
On the Configure page, in the Setup test framework section, choose XCTest. Then, select Choose File.
-
Browse to the
.zip
file that contains the XCTest package for your app and upload it. -
After the upload completes, choose Next.
-
Complete the remaining steps in the project creation process. You will select the devices that you want to test on and specify the device state.
-
After you configure your run, on the Review and start run page, choose Confirm and start run.
Device Farm runs your test and shows the results in the console.