How to Create IPA and XCTest Package for iOS Testing

  December 20, 2016

The Xcode’s XCTest framework is getting used more and more by developers and QA folks that aim to test their iOS apps efficiently. This framework is a great addition in the iOS developers’ toolbox and in order to get you up and running with it here are some basic step-by-step instructions on how to get started with XCTest and how to create IPA properly for a test session.

Methods to Create iOS Package Archive

The application and test package are both required for XCTest testing. The same thing applies to any functional UI test automation and then the application (whether IPA or APK) can be used for target devices and test package for instrumentation or to be used as part of the device session. More specific information about iOS development certificates, provisioning profiles and identifiers and how to prepare IPA for Testdroid Cloud can be found at Bitbar blog or you can download your own XCTest copy directly to learn all the essential things.

Working on Xcode to Create IPA for Testing

First, we’ll take a look at Xcode and how you should be working with it to produce IPA compatible with a device session, and with the right configurations.

1. Archive Your Build.

When you archive your build, the package will be compatible with an iOS device. When your build is done and archiving has finished, select the build from Archive list and click “Export…”:

How to Archive IPA from iOS Project

2. Select The Right Method for Export.

When the following window is shown, simply select “Save for Ad Hoc Deployment” and click Next.

Save for Ad Hoc Deployment

3. Identify Yourself (and the Build).

Use the same identify what you use in build settings for code signing. If your project and Xcode is properly configured you should see the following type of dialog proposing the first usable identifier:

Use Identifier the same way you use with code signing

4. Select Supported OS and Devices.

It’s almost always recommended to include all possible device support for your app. However, if you want to reduce the size of your IPA you can shrink it by selecting to support only certain devices and OS versions. In that case, you would select Export for specific devices and select devices from the drop-down. To support all of them (recommended), just select “Export one app for all compatible devices”:

export one app for all compatible devices

All done! Now just follow through the wizard to locate your .ipa file and everything will be ready for the test session.

Working on Command-Line to Create IPA for Testing

To get started with a command-line script you first need to make sure the .IPA file will be testable and it can be packaged properly.

1. Select to Build for Testing.

This can be done Product -> Build for -> Testing menu:

build ipa for testing using xcode

2. Locate the App File on Your Harddisk.

Next, select your project in Project Navigator and right-click to “Show it in Finder”:

select show in finder in project navigator

Figure 8 Finally, once the scenarios are defined, developers can download the feature file to implementation.

3. Copy the Application File.

After Finder dialog has been opened and files are shown, just highlight the .app file and right-click to see copying option, as follows:

copy app file to right place

4. Create the .IPA File from Command-Line

Finally, open the terminal, and create IPA package with the following command line:

$ mkdir /ProjectName
$ cd ProjectName
$ cp -r /Path/To/Your/IPA/File/ .
$ cd ..
$ zip --symlinks -qr "LocalizationDemo.ipa" ProjectName

Now you have an IPA file to be used with a test session on devices.

Create a package for XCTest

Things will start with compiling unit tests. It will actually happen automatically if you have checked the target properly. This can be done or just verified that everything is properly set up under Product -> Scheme -> Edit Scheme.

Select Target on the left-hand side menu and check all items on the Run column:

configure target properly in Xcode

This will make sure your tests will be compiled whenever your app is getting built.

The next thing you need to make sure of is that all used classes for testing are available in the test bundle and memberships are appropriately tagged. This can be done on the right-hand side menu “Target Membership” for each file. In the following example, MyModel.swift file is the one under test:

target membership in xcode ios project

Another option is to use @testable annotation for importing different modules.

Now, to compile tests for real devices, select a device to be used from the menu and press Command + B (or Product -> Build). Note that since Xcode has been changed quite a lot with the latest version, you have to deal with those tests differently based on which Xcode version you are using.

Xcode 7

In Xcode 7 you can right-click on .xctest under Product, and select Show in Finder:

xctest in Xcode 7
Xcode 8

In Xcode8 .xctest can be found inside of the .app, so in order to locate is right-click on top of the app, Show in Finder, right-click again top of the app in Finder and select Show Package Contents:

xcode 8 and xctest test package

Then go to the Plugins folder and right-click the top of the .xctest and select compress:

xctest packaging with xcode 8

Now you have XCTest package as a zip file:

xctest as a zip file

These files are now usable locally with your physical iOS devices, or alternatively with mobile device cloud. Looking for some basic material about iOS app testing? Look no further, here is all you need to know in order to get started!

Happy iOS Testing Folks!