TechnologiesDeveloper Tools & Diagnostics

XCTest

iOSmacOStvOSwatchOSvisionOS

XCTest is the testing framework for writing and running unit, performance, and UI tests across Apple platforms. You define tests by subclassing XCTestCase, group them with XCTestSuite, and verify behavior with assertions whose failures are recorded as issues through types such as XCTIssueReference and XCTMutableIssue. To validate asynchronous code, you create an XCTestExpectation and block on it with XCTWaiter, and you measure performance using metrics like XCTClockMetric, XCTCPUMetric, and XCTMemoryMetric configured through XCTMeasureOptions. You can also observe test execution with XCTestObservation and XCTestObservationCenter, capture diagnostics as an XCTAttachment, and mark known problems with XCTExpectedFailure.

Essentials 3

The base test class and the case and suite types you subclass and group to define tests.

  • Cl
    XCTest
    @class XCTest
  • Cl
    XCTestCase
    @class XCTestCase
  • Cl
    XCTestSuite
    @class XCTestSuite

Test Execution and Results 3

Objects that track the run of individual tests and suites and collect their outcomes.

  • Cl
    XCTestRun
    @class XCTestRun
  • Cl
    XCTestCaseRun
    A test run that records the execution and results of a single test case.
  • Cl
    XCTestSuiteRun
    A test run that records the execution and aggregated results of a test suite.

Asynchronous Testing 7

Expectations and waiters for validating code that completes asynchronously.

  • Cl
    XCTestExpectation
    @class XCTestExpectation
  • Cl
    XCTWaiter
    @class XCTWaiter
  • Pr
    XCTWaiterDelegate
    @protocol XCTWaiterDelegate
  • Cl
    XCTKVOExpectation
    @class XCTKVOExpectation
  • Cl
    XCTNSNotificationExpectation
    @class XCTNSNotificationExpectation
  • Cl
    XCTNSPredicateExpectation
    @class XCTNSPredicateExpectation
  • Cl
    XCTDarwinNotificationExpectation
    @class XCTDarwinNotificationExpectation

Failures and Issues 5

Types that represent, mark, and inspect the issues recorded when assertions fail.

  • Cl
    XCTIssueReference
    @class XCTIssue
  • Cl
    XCTMutableIssue
    @class XCTMutableIssue
  • Cl
    XCTExpectedFailure
    @class XCTExpectedFailure
  • St
    XCTestError
    A structure describing errors thrown by the XCTest framework, such as timeouts and skips.
  • En
    _XCTAssertionType
    An enumeration of the internal assertion kinds used to categorize recorded test failures.

Performance Measurement 11

Metrics and options for measuring and reporting the performance of code under test.

  • Pr
    XCTMetric
    @protocol XCTMetric
  • Cl
    XCTMeasureOptions
    @class XCTMeasureOptions
  • Cl
    XCTPerformanceMeasurement
    @class XCTPerformanceMeasurement
  • Cl
    XCTPerformanceMeasurementTimestamp
    @class XCTPerformanceMeasurementTimestamp
  • St
    XCTPerformanceMetric
    A structure of constants identifying the built-in performance metrics XCTest can measure.
  • Cl
    XCTClockMetriciOS 13.0+
    @class XCTClockMetric
  • Cl
    XCTCPUMetriciOS 13.0+
    @class XCTCPUMetric
  • Cl
    XCTMemoryMetriciOS 13.0+
    @class XCTMemoryMetric
  • Cl
    XCTStorageMetriciOS 13.0+
    @class XCTStorageMetric
  • Cl
    XCTOSSignpostMetriciOS 13.0+
    @class XCTOSSignpostMetric
  • Cl
    XCTApplicationLaunchMetriciOS 13.0+
    @class XCTApplicationLaunchMetric

Activities and Attachments 3

APIs for grouping test steps into activities and capturing diagnostic attachments.

  • Cl
    XCTContext
    An object that provides access to the runtime context for grouping work into named activities.
  • Pr
    XCTActivity
    Represents a test activity.
  • Cl
    XCTAttachment
    @class XCTAttachment

Source Code Context 4

Types that describe the source locations, frames, and symbols associated with a test event.

  • Cl
    XCTSourceCodeLocation
    @class XCTSourceCodeLocation
  • Cl
    XCTSourceCodeSymbolInfo
    @class XCTSourceCodeSymbolInfo
  • Cl
    XCTSourceCodeFrame
    @class XCTSourceCodeFrame
  • Cl
    XCTSourceCodeContext
    @class XCTSourceCodeContext

Observing Test Runs 3

Protocols and centers for receiving callbacks as tests and suites start and finish.

  • Pr
    XCTestObservation
    @protocol XCTestObservation
  • Cl
    XCTestObservationCenter
    @class XCTestObservationCenter
  • Cl
    XCTestObserver
    XCTestObserver is deprecated.

Logging and Internals 4

Lower-level logging, probing, and exception types used internally by the test runtime.

  • Cl
    XCTestLog
    A legacy observer that writes a textual log of test execution progress.
  • Cl
    XCTestProbe
    An internal type used to probe the state of the test runtime.
  • Cl
    _XCTestCaseInterruptionException
    An internal exception used to interrupt a test case when execution must be aborted.
  • Cl
    _XCTSkipFailureException
    An internal exception thrown to skip the remainder of a test when a skip is requested.

Type Aliases 1

  • Ty
    XCWaitCompletionHandler
    @typedef XCWaitCompletionHandler
← Developer Tools & Diagnostics