CheckOps home

Tools directory

X

CheckOps

XCTest

XCTest is Apple's testing framework for unit, performance and UI tests in Xcode projects across Apple platforms, with assertions, expectations for async code, performance metrics and code coverage.

Visit website

Latest public signals

Not refreshed yet. Refresh reads the public site and, when the entry has a GitHub repository, the latest release.

Visit Website

Introduction

XCTest is Apple’s framework for creating and running unit tests, performance tests and UI tests for Xcode projects. It is built into Xcode, works with Swift and Objective-C, and supports iOS, iPadOS, macOS, tvOS, watchOS and visionOS. An open-source implementation, swift-corelibs-xctest, provides XCTest on Linux and other platforms.

Tests are methods starting with test in subclasses of XCTestCase, using assertions such as XCTAssertEqual, XCTAssertTrue, XCTAssertNil and XCTAssertThrowsError, plus XCTUnwrap for optionals. Setup and teardown run per test or per class, and async throws tests work with Swift concurrency, while XCTestExpectation and fulfillment(of:) handle callback-based asynchrony. Performance tests use measure(metrics:) with clock, CPU, memory and storage metrics and baselines. UI tests drive apps with XCUIApplication (see XCUITest). Xcode test plans configure test configurations, parallel testing, repetition for flaky tests and code coverage, and xcodebuild test runs suites in CI.

Results are stored in .xcresult bundles that Xcode and command-line tools can inspect, including logs, attachments and screenshots captured with XCTAttachment, which helps diagnose failures from CI runs. XCTest can also run alongside Swift Testing in the same target, so existing suites do not need to be rewritten.

Features

  1. Built into Xcode: No dependencies; works across Apple platforms.
  2. Async support: async tests and expectations.
  3. Performance tests: Metrics and baselines with measure.
  4. Test plans and coverage: Configurations, parallelism, retries and coverage.

Pros

  1. Free: Included with Xcode.
  2. First-party: Apple-supported across all its platforms.

Cons

  1. Verbose assertions: Swift Testing’s #expect is more expressive.
  2. Apple-centric: Best experience requires Xcode on macOS.
import XCTest
@testable import Shop

final class OrderServiceTests: XCTestCase {
    var service: OrderService!

    override func setUp() {
        service = OrderService(api: FakeAPI())
    }

    func testPlacesOrder() async throws {
        let order = try await service.place(items: [.apple])
        XCTAssertEqual(order.status, .confirmed)
    }

    func testPerformance() {
        measure { _ = service.priceAll(Array(repeating: .apple, count: 10_000)) }
    }
}
xcodebuild test -scheme Shop -destination 'platform=iOS Simulator,name=iPhone 16'

Resources:

Pricing

Free with Xcode.

  1. All Apple-platform developers, especially for UI and performance tests.
  2. Existing suites that predate Swift Testing.

Conclusion

XCTest is the foundation of testing on Apple platforms; new unit tests may use Swift Testing, but XCTest remains essential for UI and performance testing.

Alternatives

Other tools on CheckOps that cover similar ground. Open a page, or compare one with XCTest side by side.