XCTest

Write and run unit, performance and UI tests for your Xcode projects.

Introduced
2013
Xcode 5
Kind
Framework
Runs on
Xcode 5 or later
Get it from
Included with Xcode
iOS
iPadOS
Mac Catalyst
macOS
tvOS
visionOS
watchOS

Overview

XCTest is Apple's original testing framework for Xcode projects. Tests are methods on XCTestCase subclasses that check conditions with assertions such as XCTAssertEqual and record a failure when a condition isn't met. Test methods can be marked async to test Swift concurrency code, and performance tests measure a block of code against a baseline. UI tests use XCUIApplication and related classes, now part of the XCUIAutomation framework that XCTest imports, to launch an app and drive its interface.

Swift Testing, added in Xcode 16, is now recommended for new unit tests. The two frameworks can share a test target, and Apple still recommends XCTest for UI and performance tests.

Unit tests

XCTestCase subclasses with assertions, setup, teardown and async test methods.

UI automation

Launch the app with XCUIApplication, find elements and simulate user input.

Performance tests

measure(metrics:block:) records metrics and compares them to a baseline.

Accessibility audits

performAccessibilityAudit checks an app's UI for accessibility issues in a test.

RecipeTests.swift
import XCTest @testable import BrewKit final class RecipeTests: XCTestCase { func testWaterForDose() { XCTAssertEqual(Recipe(ratio: 16).water(forDose: 15), 240) } func testParsesBundledRecipes() async throws { let recipes = try await RecipeLoader().loadBundled() XCTAssertFalse(recipes.isEmpty) } }

History

How it grew up.

2013

XCTest

Xcode 5 introduces XCTest as the default test framework, replacing OCUnit.

2015

UI testing

Xcode 7 adds UI testing to XCTest, with XCUIApplication and UI recording.

2019

Test plans

Xcode 11 adds test plans for running tests under several configurations.

2021

Async tests

Test methods can be marked async to test Swift concurrency code directly.

2026

Framework interoperability

Xcode 27 lets XCTest and Swift Testing APIs be called across frameworks.