<!--
{
  "availability" : [
    "xcode: 5.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "XCTest",
  "identifier" : "/documentation/XCTest",
  "metadataVersion" : "0.1.0",
  "role" : "Framework",
  "symbol" : {
    "kind" : "Framework",
    "modules" : [
      "XCTest"
    ],
    "preciseIdentifier" : "XCTest"
  },
  "title" : "XCTest"
}
-->

# 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 aren’t satisfied. Tests can also measure the performance of blocks of code to check for performance regressions.
Use XCTest in combination with <doc://com.apple.documentation/documentation/XCUIAutomation> to interact with an application’s UI and validate user interaction flows. For more information, see <doc://com.apple.documentation/documentation/XCUIAutomation/recording-ui-automation-for-testing>.

> Tip:
> Xcode 16 and later includes Swift Testing, a framework for writing unit tests that takes advantage of the powerful capabilities of the Swift programming language. Consider using Swift Testing for new unit test development and migrating existing tests as described in <doc://com.apple.documentation/documentation/Testing/MigratingFromXCTest>. A test target can contain tests using both Swift Testing and XCTest, however don’t mix API from the two frameworks in the same test. Continue to use XCTest for user interface tests and <doc://com.apple.xctest/documentation/XCTest/performance-tests>.

## Topics

### Test cases and test methods

[Defining Test Cases and Test Methods](/documentation/XCTest/defining-test-cases-and-test-methods)

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

[`XCTestCase`](/documentation/XCTest/XCTestCase)

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

[`XCTest`](/documentation/XCTest/XCTest)

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

### Test assertions

[Boolean Assertions](/documentation/XCTest/boolean-assertions)

Test a condition that generates a true or false result.

[Nil and Non-Nil Assertions](/documentation/XCTest/nil-and-non-nil-assertions)

Check whether a test condition has, or doesn’t have, a value.

[Equality and Inequality Assertions](/documentation/XCTest/equality-and-inequality-assertions)

Check whether two values are equal or unequal.

[Comparable Value Assertions](/documentation/XCTest/comparable-value-assertions)

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

[Error Assertions](/documentation/XCTest/error-assertions)

Check whether a function call throws, or doesn’t throw, an error.

[NSException Assertions](/documentation/XCTest/nsexception-assertions)

Check whether a function call throws, or doesn’t throw, an exception.

[Unconditional Test Failures](/documentation/XCTest/unconditional-test-failures)

Generate a failure immediately and unconditionally.

[Expected Failures](/documentation/XCTest/expected-failures)

Anticipate known test failures to prevent failing tests from affecting your workflows.

[Methods for Skipping Tests](/documentation/XCTest/methods-for-skipping-tests)

Skip tests when meeting specified conditions.

### Asynchronous tests

[Asynchronous Tests and Expectations](/documentation/XCTest/asynchronous-tests-and-expectations)

Verify that asynchronous code behaves as expected.

### UI tests

  <doc://com.apple.documentation/documentation/XCUIAutomation>

### Performance tests

[Performance Tests](/documentation/XCTest/performance-tests)

Gather metrics while running your code, and report a failure if the metrics become significantly worse than a baseline value.

### Activities and attachments

[Activities and Attachments](/documentation/XCTest/activities-and-attachments)

Split long tests into substeps with activities, and attach output data like files and screenshots.

### Test execution

[Test Execution and Observation](/documentation/XCTest/test-execution-and-observation)

Observe, introspect, and customize the test execution flow.

### Deprecated

[Deprecated Symbols](/documentation/XCTest/deprecated-symbols)

These symbols are deprecated and are no longer recommended.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)