---
description: In this iOS Automation Testing tutorial, you will learn How to Create iOS Automation with Xcode using UI Automation Framework and OC Unit Framework.
title: iOS Automation Testing with Xcode UI Framework
image: https://www.guru99.com/images/ios-automation-testing-with-xcode-ui-framework.png
---

[Skip to content](#main)

**⚡ Smart Summary**

iOS automation testing with Xcode records and replays user interface actions against an application under test, following a test-driven cycle of design, test, implement and test again until every case passes.

- 🔘 **TDD cycle:** Design, test, implement and test again form the four phases applied to iOS application testing.
- ☑️ **Prerequisites:** A Mac running OS X with the Xcode IDE, an automation framework and the iOS SDK installed.
- ✅ **Instruments route:** The Automation instrument records a script, shows it in the script log, and replays it on demand.
- 🧪 **OCUnit route:** A Unit Test Bundle target, an active scheme, a test group and a test class written in Objective-C.
- ⚠️ **Deprecation:** The UIAutomation instrument was deprecated in Xcode 8 and removed; XCUITest is the supported successor.
- 🛠️ **Modern equivalent:** A UI Testing Bundle target plus XCUIApplication queries replaces the recorded Instruments script.

Read More

![iOS automation testing with the Xcode UI Automation framework running a recorded script against an app](https://www.guru99.com/images/ios-automation-testing-with-xcode-ui-framework.png)

## iOS Automation Testing using Xcode

To guarantee the quality of your iOS application, you should follow the test-driven development process shown in the figure below.

[![Test-driven development cycle for iOS automation testing showing design, test, implement and re-test phases](https://www.guru99.com/images/iOStestprogram1.png)](https://www.guru99.com/images/iOStestprogram1.png)

Test-Driven Development (TDD) is a [testing](https://www.guru99.com/software-testing.html) model which is applied to iOS application testing, and it sits inside the wider practice of [mobile testing](https://www.guru99.com/mobile-testing.html). In this model, a tester has to follow the 4 phases below:

- **Design:** Figure out what you want to test and design your test cases.
- **Test:** Run all tests and see if any test cases fail.
- **Implement:** Revise your code and fix the bugs that caused the test to fail.
- **Test again:** If a test fails, roll back to the design. If all test cases pass, the code meets the entire tested requirement.

## Setting up Xcode Project for UI Testing

To create an iOS test program you need a Mac. Your Mac must already have the following installed:

- **OS X** — the operating system for a Mac.
- **Xcode IDE** — the development tool for iOS.
- **An automated testing framework** — UI Automation, OCUnit, and so on.
- **iOS SDK 4** or higher.

**⚠️ Version note:** The prerequisites above describe the toolchain of the era in which the two walkthroughs that follow were written. On a current Mac, Xcode ships the XCTest and XCUITest frameworks in the box, and the separate UI Automation instrument is no longer part of the installation. The original steps are preserved below because they document how the framework worked, and the modern equivalent is described further down.

## How to Create iOS Automation using UI Automation Framework

The eight steps below record a script with the Automation instrument and replay it against the application under test.

**Step 1) Launch Instruments**

Open XCode -> Open Developer Tool -> Instrument

[![Opening Instruments from the Xcode Open Developer Tool menu]()](https://www.guru99.com/images/iOStestprogram2.png)

**Step 2) Add Automation Instrument**

In the Instruments window, select the Automation instrument.

[![Selecting the Automation instrument in the Instruments template chooser]()](https://www.guru99.com/images/iOStestprogram3.png)

To create a test script, you either record a [test scenario](https://www.guru99.com/test-scenario.html) or you program it manually.

**Step 3) Press Red button**

An instrument is launching — stop the recording immediately. If you want to start the recording, press the red button.

[![Red record button in the Instruments toolbar used to start and stop a trace]()](https://www.guru99.com/images/iOStestprogram4.png)

**Step 4) Create a new script**

In the Scripts window, click Add > Create to create a new script.

[![Add and Create menu in the Instruments Scripts window for a new automation script]()](https://www.guru99.com/images/iOStestprogram5.png)

**Step 5) Choose the target**

You are now in the Trace window. Use the Choose Target pull-down to navigate to the debugging version of your app.

[![Choose Target pull-down in the Instruments Trace window pointing at the debug build]()](https://www.guru99.com/images/iOStestprogram6.png)

In this case, Apple’s sample [SimpleDrillDown](https://developer.apple.com/library/archive/samplecode/SimpleDrillDown/index.html) app is used as the application under test. It has the GUI shown below.

[![SimpleDrillDown sample application interface used as the application under test]()](https://www.guru99.com/images/iOStestprogram7.png)

**Step 6) Start record your script**

Record your script by hitting the record button at the top or bottom of the tool.

[![Record button at the edge of the Instruments window that starts script capture]()](https://www.guru99.com/images/iOStestprogram8.png)

Now you can perform some UI actions on your application under test, and your script is recorded.

**Step 7) See your script**

To see your script, hit the Trace Log / Editor Log drop-down and switch to the script log view.

[![Trace Log and Editor Log drop-down used to switch to the script log view]()](https://www.guru99.com/images/iOStestprogram9.png)

You will see your recorded script.

[![Recorded UI Automation script displayed in the Instruments script log view]()](https://www.guru99.com/images/iOStestprogram10.png)

**Step 8) Play your script**

Press the play button. The script runs, and you can stop it after the logs appear.

[![Playback of the recorded automation script with log output in the Instruments window]()](https://www.guru99.com/images/iOStestprogram11.png)

**⚠️ Historical note:** The Automation instrument used in these eight steps was deprecated in Xcode 8 and later removed, so it is no longer present in current Xcode installations. The steps are retained here as a record of how the framework worked; for new work, use the XCUITest walkthrough further down this page.

**Don't Miss:**

- [iOS App Testing Tutorial](https://www.guru99.com/getting-started-with-ios-testing.html)
- [Robotium Tutorial: Android Testing Framework with Example](https://www.guru99.com/first-android-testing.html)
- [6 BEST Mobile App Testing Tools (2026)](https://www.guru99.com/mobile-testing-tools.html)
- [Android Debug Bridge (ADB) Connect to Device over USB, WiFi](https://www.guru99.com/adb-connect.html)

## How to Create iOS Automation using OCUnit framework

The second route places the tests inside the Xcode project itself rather than inside Instruments.

**Step 1) Start Xcode IDE, Add Unit Test Bundle target**

[![Adding a Unit Test Bundle target to an existing Xcode project]()](https://www.guru99.com/images/iOStestprogram12.png)

**Step 2) Write the name of the new Unit Test Bundle** as shown in the figure above, then click Finish.

**Step 3) Make Unit Test the active target**

[![Selecting the unit test bundle as the active target in Xcode]()](https://www.guru99.com/images/iOStestprogram13.png)

**Step 4) Add a group for test classes**

[![Creating a project group to hold the iOS unit test classes]()](https://www.guru99.com/images/iOStestprogram14.png)

**Step 5) Add a Unit test class**

[![Adding a new unit test class file inside the test group in Xcode]()](https://www.guru99.com/images/iOStestprogram15.png)

**Step 6) Now start your implementation**

[![Empty unit test class in the Xcode editor ready for the test implementation]()](https://www.guru99.com/images/iOStestprogram16.png)

OCUnit uses the Objective-C language to create the test program, so the developer must know that language. Modern Xcode versions ship [unit testing](https://www.guru99.com/unit-testing-guide.html) through XCTest instead, which supports both Objective-C and Swift, but the target-and-class structure shown in these six steps is unchanged.

## UIAutomation vs XCUITest: What Changed

Because both frameworks used above belong to an earlier generation of the Apple toolchain, it is worth being precise about what replaced them and why.

| **Aspect** | **UI Automation (Instruments)** | **XCUITest** |
| --- | --- | --- |
| Status | Deprecated in Xcode 8 and removed from later releases | Apple’s supported UI testing framework |
| Where tests live | Scripts inside an Instruments trace document | A UI Testing Bundle target inside the Xcode project |
| Language | JavaScript | Swift or Objective-C |
| Test runner | The Automation instrument | XCTest, the same runner as unit tests |
| Continuous integration | Awkward — driven through Instruments | Runs from the command line alongside unit tests |
| Recording | Record button in the Instruments toolbar | Record button in the Xcode editor, which emits Swift |

The practical consequence is that an XCUITest suite is ordinary project source code. It is reviewed, versioned and executed like the rest of the codebase, which is the main reason the recorded-trace model disappeared.

## How to Write an iOS UI Test with XCUITest

The modern equivalent of the eight Instruments steps is short. The structure below mirrors the same record-then-replay idea, but the output is a source file rather than a trace.

1. **Add the target.** In Xcode choose File > New > Target and pick the UI Testing Bundle template, or tick the option to include tests when creating a new project.
2. **Open the generated test class.** Xcode creates an XCTestCase subclass with empty setup and test methods.
3. **Launch the app under test.** Create an XCUIApplication instance and call launch on it, which starts the app in a separate process.
4. **Query and act.** Reach elements through the element queries — buttons, tables, static texts — and call tap, typeText or swipe on them.
5. **Assert.** Use XCTAssert to verify that the expected element exists after the action.
6. **Run.** Execute the test from the Xcode test navigator, or from the command line so the same suite runs in continuous integration.

A minimal test follows this shape:

```
import XCTest

final class AppUITests: XCTestCase {

    func testTappingFirstRowShowsDetail() {
        let app = XCUIApplication()
        app.launch()

        // act on the first row of the list
        app.tables.cells.element(boundBy: 0).tap()

        // verify that the next screen appeared
        XCTAssertTrue(app.staticTexts.firstMatch.waitForExistence(timeout: 5))
    }
}
```

The recorder still exists: placing the cursor inside a test method and pressing the record button in the editor generates these queries automatically, which is the direct descendant of Step 6 above. The wider principles of [automation testing](https://www.guru99.com/automation-testing.html) apply unchanged.

## UI Automation Sample Code

This article includes some source code examples. They help you understand the tutorial more clearly and quickly.

[UI Automation Sample](https://drive.google.com/uc?export=download&id=0B_vqvT0ovzHcalpPZE5RbXExQm8) — test script for the UI Automation demo.

## FAQs

🍎 Can iOS UI tests run without a Mac?

No. Xcode and the iOS simulators run only on macOS, so a Mac is required either locally or as a hosted build machine. Cloud device farms and hosted CI providers exist precisely so teams without Mac hardware can still execute the suite.

🤖 How does AI speed up iOS UI test maintenance?

Machine learning models suggest replacement element queries when a screen changes, cluster flaky failures by root cause, and rank which failed runs are genuine regressions. This matters for UI suites, where small layout edits otherwise break many selectors at once.

🧑‍💻 Is GitHub Copilot useful for writing XCUITest code?

It handles the repetitive parts well — test class scaffolding, launch arguments, page-object wrappers and assertion boilerplate. Element identifiers still have to match the real app, so every generated query needs verification against the running build before it is trusted.

🔗 How does Appium relate to XCUITest?

Appium drives iOS through its XCUITest driver, which replaced the older UIAutomation driver. The advantage is one cross-platform test language for iOS and Android; the trade-off is an extra layer between the test and Apple’s own runner.

⚖️ What is the difference between a unit test and a UI test in Xcode?

A unit test runs inside the app process and calls your code directly. A UI test launches the app as a separate process and interacts only through the interface, so it is slower but validates what the user actually experiences.

📱 Should iOS UI tests run on a simulator or a real device?

Simulators are faster and fine for most functional flows in a pipeline. Real devices are needed for camera, biometrics, push notifications, performance and anything touching hardware sensors, so most teams run both at different points in the cycle.

🐢 Why are iOS UI tests slow and flaky, and what helps?

Each test relaunches the app and waits on animations. Stability improves when you set accessibility identifiers instead of matching on labels, wait for element existence rather than sleeping, reset state between tests, and keep each case focused on one journey.

🗂️ Can an old UIAutomation JavaScript suite be migrated automatically?

Not directly, because the languages and element models differ. The usual path is to keep the old scripts as documentation of intended coverage, then rewrite each scenario as an XCUITest case, starting with the journeys that fail most often in production.

#### Summarize this post with:

ChatGPT Perplexity Grok Google AI

**Stay Updated on AI** **Get Weekly AI Skills, Trends, Actionable Advice.**

##### Sign up for the newsletter

Subscribe for Free

You have successfully subscribed.  
Please check your inbox.

![AI-Newsletter]() Chosen by over **350,000+** professionals

[Scroll to top](#wrapper)

×

Search for:

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://www.guru99.com/#organization","name":"Guru99","sameAs":["https://www.facebook.com/Guru99Official","https://twitter.com/guru99com"],"logo":{"@type":"ImageObject","@id":"https://www.guru99.com/#logo","url":"https://www.guru99.com/images/guru99-logo-v1-150x59.png","contentUrl":"https://www.guru99.com/images/guru99-logo-v1-150x59.png","caption":"Guru99","inLanguage":"en-US"}},{"@type":"WebSite","@id":"https://www.guru99.com/#website","url":"https://www.guru99.com","name":"Guru99","publisher":{"@id":"https://www.guru99.com/#organization"},"inLanguage":"en-US"},{"@type":"ImageObject","@id":"https://www.guru99.com/images/ios-automation-testing-with-xcode-ui-framework.png","url":"https://www.guru99.com/images/ios-automation-testing-with-xcode-ui-framework.png","width":"700","height":"250","caption":"iOS Automation Testing with Xcode UI Framework","inLanguage":"en-US"},{"@type":"BreadcrumbList","@id":"https://www.guru99.com/ios-test-program-uiautomation-framework.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":"1","item":{"@id":"https://www.guru99.com","name":"Home"}},{"@type":"ListItem","position":"2","item":{"@id":"https://www.guru99.com/mobile-testing","name":"Mobile Apps Testing"}},{"@type":"ListItem","position":"3","item":{"@id":"https://www.guru99.com/ios-test-program-uiautomation-framework.html","name":"iOS Automation Testing with Xcode UI Framework"}}]},{"@type":"WebPage","@id":"https://www.guru99.com/ios-test-program-uiautomation-framework.html#webpage","url":"https://www.guru99.com/ios-test-program-uiautomation-framework.html","name":"iOS Automation Testing with Xcode UI Framework","dateModified":"2026-10-09T19:12:36+05:30","isPartOf":{"@id":"https://www.guru99.com/#website"},"primaryImageOfPage":{"@id":"https://www.guru99.com/images/ios-automation-testing-with-xcode-ui-framework.png"},"inLanguage":"en-US","breadcrumb":{"@id":"https://www.guru99.com/ios-test-program-uiautomation-framework.html#breadcrumb"}},{"@type":"Person","@id":"https://www.guru99.com/author/editorial","name":"Editorial Team","url":"https://www.guru99.com/author/editorial","image":{"@type":"ImageObject","@id":"https://www.guru99.com/images/favicon-new-logo.png","url":"https://www.guru99.com/images/favicon-new-logo.png","caption":"Editorial Team","inLanguage":"en-US"},"sameAs":["https://www.guru99.com/editorial-team"],"worksFor":{"@id":"https://www.guru99.com/#organization"}},{"articleSection":"Mobile Apps Testing","headline":"iOS Automation Testing with Xcode UI Framework","description":"In this iOS Automation Testing tutorial, you will learn How to Create iOS Automation with Xcode using UI Automation Framework and OC Unit Framework.","keywords":"mobile","speakable":{"@type":"SpeakableSpecification","cssSelector":[".entry-title",".summary"]},"@type":"Article","author":{"@id":"https://www.guru99.com/author/editorial","name":"Editorial Team"},"dateModified":"2026-10-09T19:12:36+05:30","image":{"@id":"https://www.guru99.com/images/ios-automation-testing-with-xcode-ui-framework.png"},"copyrightYear":"2026","name":"iOS Automation Testing with Xcode UI Framework","subjectOf":[{"@type":"HowTo","name":"How to Create iOS Automation using UI Automation Framework","description":"Following is a step by step process on How to Create iOS Automation using UI Automation Framework","step":[{"@type":"HowToStep","name":"Step 1) Launch Instruments","text":"Open XCode -&gt;Open Developer Tool -&gt;Instrument","image":"https://www.guru99.com/images/iOStestprogram2.png","url":"https://www.guru99.com/ios-test-program-uiautomation-framework.html#step1"},{"@type":"HowToStep","name":"Step 2) Add Automation Instrument","text":"In Instruments window, select Automation Instrument","image":"https://www.guru99.com/images/iOStestprogram3.png","url":"https://www.guru99.com/ios-test-program-uiautomation-framework.html#step2"},{"@type":"HowToStep","name":"Step 3) Press Red button","text":"An instrument is launching, and Stop recording immediately. If you want to start the record, press Red button","image":"https://www.guru99.com/images/iOStestprogram4.png","url":"https://www.guru99.com/ios-test-program-uiautomation-framework.html#step3"},{"@type":"HowToStep","name":"Step 4) Create a new script","text":"In the Scripts window, click Add &gt; Create to create a new script","image":"https://www.guru99.com/images/iOStestprogram5.png","url":"https://www.guru99.com/ios-test-program-uiautomation-framework.html#step4"},{"@type":"HowToStep","name":"Step 5) Choose the target","text":"You\u2019re in the Trace window, use the Choose Target pull down to navigate to the debugging version of your App.","image":"https://www.guru99.com/images/iOStestprogram6.png","url":"https://www.guru99.com/ios-test-program-uiautomation-framework.html#step5"},{"@type":"HowToStep","name":"Step 6) Start record your script","text":"Record your script by hitting the record button at the top or bottom of the tool.","image":"https://www.guru99.com/images/iOStestprogram8.png","url":"https://www.guru99.com/ios-test-program-uiautomation-framework.html#step6"},{"@type":"HowToStep","name":"Step 7) See your script","text":"To see your script, hit the Trace Log/Editor Log drop down and switch to script log view.","image":"https://www.guru99.com/images/iOStestprogram9.png","url":"https://www.guru99.com/ios-test-program-uiautomation-framework.html#step7"},{"@type":"HowToStep","name":"Step 8) Play your script","text":"Press play button, the script runs, and you can stop it after logs appear.","image":"https://www.guru99.com/images/iOStestprogram11.png","url":"https://www.guru99.com/ios-test-program-uiautomation-framework.html#step8"}]},{"@type":"FAQPage","mainEntity":[{"@type":"Question","name":"Can iOS UI tests run without a Mac?","acceptedAnswer":{"@type":"Answer","text":"No. Xcode and the iOS simulators run only on macOS, so a Mac is required either locally or as a hosted build machine. Cloud device farms and hosted CI providers exist precisely so teams without Mac hardware can still execute the suite."}},{"@type":"Question","name":"How does AI speed up iOS UI test maintenance?","acceptedAnswer":{"@type":"Answer","text":"Machine learning models suggest replacement element queries when a screen changes, cluster flaky failures by root cause, and rank which failed runs are genuine regressions. This matters for UI suites, where small layout edits otherwise break many selectors at once."}},{"@type":"Question","name":"Is GitHub Copilot useful for writing XCUITest code?","acceptedAnswer":{"@type":"Answer","text":"It handles the repetitive parts well \u2014 test class scaffolding, launch arguments, page-object wrappers and assertion boilerplate. Element identifiers still have to match the real app, so every generated query needs verification against the running build before it is trusted."}},{"@type":"Question","name":"How does Appium relate to XCUITest?","acceptedAnswer":{"@type":"Answer","text":"Appium drives iOS through its XCUITest driver, which replaced the older UIAutomation driver. The advantage is one cross-platform test language for iOS and Android; the trade-off is an extra layer between the test and Apple's own runner."}},{"@type":"Question","name":"What is the difference between a unit test and a UI test in Xcode?","acceptedAnswer":{"@type":"Answer","text":"A unit test runs inside the app process and calls your code directly. A UI test launches the app as a separate process and interacts only through the interface, so it is slower but validates what the user actually experiences."}},{"@type":"Question","name":"Should iOS UI tests run on a simulator or a real device?","acceptedAnswer":{"@type":"Answer","text":"Simulators are faster and fine for most functional flows in a pipeline. Real devices are needed for camera, biometrics, push notifications, performance and anything touching hardware sensors, so most teams run both at different points in the cycle."}},{"@type":"Question","name":"Why are iOS UI tests slow and flaky, and what helps?","acceptedAnswer":{"@type":"Answer","text":"Each test relaunches the app and waits on animations. Stability improves when you set accessibility identifiers instead of matching on labels, wait for element existence rather than sleeping, reset state between tests, and keep each case focused on one journey."}},{"@type":"Question","name":"Can an old UIAutomation JavaScript suite be migrated automatically?","acceptedAnswer":{"@type":"Answer","text":"Not directly, because the languages and element models differ. The usual path is to keep the old scripts as documentation of intended coverage, then rewrite each scenario as an XCUITest case, starting with the journeys that fail most often in production."}}]}],"@id":"https://www.guru99.com/ios-test-program-uiautomation-framework.html#schema-144916","isPartOf":{"@id":"https://www.guru99.com/ios-test-program-uiautomation-framework.html#webpage"},"publisher":{"@id":"https://www.guru99.com/#organization"},"inLanguage":"en-US","mainEntityOfPage":{"@id":"https://www.guru99.com/ios-test-program-uiautomation-framework.html#webpage"}}]}
```
