Framework

XCTest

Create and run unit tests, performance tests, and UI tests for your Xcode project.

Overview

Use the XCTest framework to write unit tests for your Xcode projects that integrate seamlessly with Xcode's testing workflow.

Tests assert that certain conditions are satisfied during code execution, and record test failures (with optional messages) if those conditions are not satisfied. Tests can also measure the performance of blocks of code to check for performance regressions, and can interact with an application's UI to validate user interaction flows.

Topics

Test Cases and Test Methods

A test method is a small, self-contained method that tests a specific part of your code. A test case is a group of related test methods.

Defining Test Cases and Test Methods

Add test cases and test methods to a test target to confirm that your code behaves as expected.

class XCTestCase

The primary class for defining test cases, test methods, and performance tests.

class XCTest

An abstract base class for creating, managing, and executing tests.

Test Assertions

Use test assertions to check for expected values and outcomes in test methods.

Boolean Assertions

Test a condition that generates a true or false result.

Nil and Non-nil Assertions

Check whether a test condition is nil or non-nil.

Equality and Inequality Assertions

Check whether two values are equal or unequal.

Comparable Value Assertions

Compare two values to determine whether one is larger or smaller than the other.

Error Assertions

Check whether a function call throws (or does not throw) an error.

Failing Unconditionally

Generate a failure immediately and unconditionally.

Asynchronous Tests

Asynchronous Tests and Expectations

Perform long-running or background tasks and wait for them to satisfy expected conditions.

UI Tests

User Interface Tests

Make sure that your app's user interface behaves correctly when expected actions are performed.

Activities and Attachments

Activities and Attachments

Split long tests into substeps with activities. Attach output data such as files and screenshots to tests and activities.

Test Execution

Test Execution and Observation

Observe, introspect, and customize the test execution flow.

Deprecated

Deprecated Symbols

These symbols are deprecated and are no longer recommended.