Over a million developers have joined DZone.

How to Create IPA and XCTest Package for iOS Testing

DZone's Guide to

How to Create IPA and XCTest Package for iOS Testing

New to XCTest and ready to get your feet wet? 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.

· Mobile Zone
Free Resource

Discover how to focus on operators for Reactive Programming and how they are essential to react to data in your application.  Brought to you in partnership with Wakanda

 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 to an iOS developer's 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 for 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.

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 dropdown. 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 command line script you first need to make sure 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

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 IPA from Command Line.

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

$ mkdir /ProjectName $ cd ProjectName $ cp -r /Path/To/Your/IPA/File/LocalizationDemo.app . $ 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 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 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 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 device, select 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 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 real, physical iOS devices, or alternatively with a mobile app testing cloud service.

Learn how divergent branches can appear in your repository and how to better understand why they are called “branches".  Brought to you in partnership with Wakanda

mobile ,ios ,xcode

Published at DZone with permission of Ville-Veikko Helppi, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.


Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.


{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}