---
title: XCTestCase
framework: xctest
role: symbol
role_heading: Class
path: xctest/xctestcase
---

# XCTestCase

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

## Declaration

```swift
class XCTestCase
```

## Mentioned in

Defining Test Cases and Test Methods Set Up and Tear Down State in Your Tests Adding Attachments to Tests, Activities, and Issues Grouping Tests into Substeps with Activities

## Overview

Overview A test case is a group of related test methods, with optional setup and teardown before and after tests run. See Defining Test Cases and Test Methods for more information. XCTestCase conforms to XCTActivity, so you can simplify complex tests by organizing them into activities, and attach output to tests for later analysis. For more information, see Activities and Attachments. Create tests for asynchronous operations using expectations. For more information, see Testing Asynchronous Operations with Expectations. If your app uses Swift Concurrency, annotate test methods with async or async throws instead to test asynchronous operations, and use standard Swift concurrency patterns in your tests. Create tests to measure performance for specific blocks of code using the methods in the Measuring Performance section below. Build performance tests as part of a continuous improvement cycle for performance in your app. For more information, see Improving your app’s performance.

## Topics

### Customizing Test Setup and Teardown

- [Set Up and Tear Down State in Your Tests](xctest/set-up-and-tear-down-state-in-your-tests.md)
- [setUp()](xctest/xctestcase/setup().md)
- [addTeardownBlock(_:)](xctest/xctestcase/addteardownblock(_:)-2guon.md)
- [addTeardownBlock(_:)](xctest/xctestcase/addteardownblock(_:)-5zw6c.md)
- [tearDown()](xctest/xctestcase/teardown().md)

### Managing Test Case Execution

- [runsForEachTargetApplicationUIConfiguration](xctest/xctestcase/runsforeachtargetapplicationuiconfiguration.md)
- [continueAfterFailure](xctest/xctestcase/continueafterfailure.md)
- [executionTimeAllowance](xctest/xctestcase/executiontimeallowance.md)

### Measuring Performance

- [measure(_:)](xctest/xctestcase/measure(_:).md)
- [measureMetrics(_:automaticallyStartMeasuring:for:)](xctest/xctestcase/measuremetrics(_:automaticallystartmeasuring:for:).md)
- [measure(metrics:block:)](xctest/xctestcase/measure(metrics:block:).md)
- [measure(metrics:options:block:)](xctest/xctestcase/measure(metrics:options:block:).md)
- [measure(options:block:)](xctest/xctestcase/measure(options:block:).md)
- [startMeasuring()](xctest/xctestcase/startmeasuring().md)
- [stopMeasuring()](xctest/xctestcase/stopmeasuring().md)
- [defaultPerformanceMetrics](xctest/xctestcase/defaultperformancemetrics.md)
- [defaultMetrics](xctest/xctestcase/defaultmetrics.md)
- [defaultMeasureOptions](xctest/xctestcase/defaultmeasureoptions.md)
- [XCTPerformanceMetric](xctest/xctperformancemetric.md)

### Creating Asynchronous Test Expectations

- [expectation(description:)](xctest/xctestcase/expectation(description:).md)
- [expectation(for:evaluatedWith:handler:)](xctest/xctestcase/expectation(for:evaluatedwith:handler:).md)
- [expectation(forNotification:object:handler:)](xctest/xctestcase/expectation(fornotification:object:handler:).md)
- [expectation(forNotification:object:notificationCenter:handler:)](xctest/xctestcase/expectation(fornotification:object:notificationcenter:handler:).md)
- [keyValueObservingExpectation(for:keyPath:expectedValue:)](xctest/xctestcase/keyvalueobservingexpectation(for:keypath:expectedvalue:).md)
- [expectation(that:on:options:willEqual:)](xctest/xctestcase/expectation(that:on:options:willequal:).md)
- [keyValueObservingExpectation(for:keyPath:handler:)](xctest/xctestcase/keyvalueobservingexpectation(for:keypath:handler:).md)
- [expectation(that:on:options:willSatisfy:)](xctest/xctestcase/expectation(that:on:options:willsatisfy:)-6itb.md)
- [expectation(that:on:options:willSatisfy:)](xctest/xctestcase/expectation(that:on:options:willsatisfy:)-292oj.md)
- [expectation(that:on:options:willSatisfy:)](xctest/xctestcase/expectation(that:on:options:willsatisfy:)-85or0.md)

### Waiting for Expectations

- [fulfillment(of:timeout:enforceOrder:)](xctest/xctestcase/fulfillment(of:timeout:enforceorder:).md)
- [wait(for:)](xctest/xctestcase/wait(for:).md)
- [wait(for:enforceOrder:)](xctest/xctestcase/wait(for:enforceorder:).md)
- [wait(for:timeout:)](xctest/xctestcase/wait(for:timeout:).md)
- [wait(for:timeout:enforceOrder:)](xctest/xctestcase/wait(for:timeout:enforceorder:).md)
- [waitForExpectations(timeout:handler:)](xctest/xctestcase/waitforexpectations(timeout:handler:).md)
- [XCWaitCompletionHandler](xctest/xcwaitcompletionhandler.md)
- [XCTestError](xctest/xctesterror.md)
- [XCTestError.Code](xctest/xctesterror/code.md)
- [XCTestErrorDomain](xctest/xctesterrordomain.md)

### Monitoring UI Interruptions

- [Handling UI Interruptions](xctest/handling-ui-interruptions.md)
- [addUIInterruptionMonitor(withDescription:handler:)](xctest/xctestcase/adduiinterruptionmonitor(withdescription:handler:).md)
- [removeUIInterruptionMonitor(_:)](xctest/xctestcase/removeuiinterruptionmonitor(_:).md)

### Creating Tests Programmatically

- [init(invocation:)](xctest/xctestcase/init(invocation:).md)
- [init(selector:)](xctest/xctestcase/init(selector:).md)
- [testInvocations](xctest/xctestcase/testinvocations.md)
- [invocation](xctest/xctestcase/invocation.md)
- [invokeTest()](xctest/xctestcase/invoketest().md)
- [record(_:)](xctest/xctestcase/record(_:).md)
- [recordFailure(withDescription:inFile:atLine:expected:)](xctest/xctestcase/recordfailure(withdescription:infile:atline:expected:).md)
- [defaultTestSuite](xctest/xctestcase/defaulttestsuite.md)

## Relationships

### Inherits From

- [XCTest](xctest/xctest.md)

### Conforms To

- [CVarArg](swift/cvararg.md)
- [Copyable](swift/copyable.md)
- [CustomDebugStringConvertible](swift/customdebugstringconvertible.md)
- [CustomStringConvertible](swift/customstringconvertible.md)
- [Equatable](swift/equatable.md)
- [Escapable](swift/escapable.md)
- [Hashable](swift/hashable.md)
- [NSObjectProtocol](objectivec/nsobjectprotocol.md)
- [XCTActivity](xctest/xctactivity.md)
- [XCTWaiterDelegate](xctest/xctwaiterdelegate.md)

## See Also

### Test cases and test methods

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