XCTestCase
The primary class for defining test cases, test methods, and performance tests.
Declaration
class XCTestCaseMentioned in
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
Managing Test Case Execution
Measuring Performance
measure(_:)measureMetrics(_:automaticallyStartMeasuring:for:)measure(metrics:block:)measure(metrics:options:block:)measure(options:block:)startMeasuring()stopMeasuring()defaultPerformanceMetricsdefaultMetricsdefaultMeasureOptionsXCTPerformanceMetric
Creating Asynchronous Test Expectations
expectation(description:)expectation(for:evaluatedWith:handler:)expectation(forNotification:object:handler:)expectation(forNotification:object:notificationCenter:handler:)keyValueObservingExpectation(for:keyPath:expectedValue:)expectation(that:on:options:willEqual:)keyValueObservingExpectation(for:keyPath:handler:)expectation(that:on:options:willSatisfy:)expectation(that:on:options:willSatisfy:)expectation(that:on:options:willSatisfy:)
Waiting for Expectations
fulfillment(of:timeout:enforceOrder:)wait(for:)wait(for:enforceOrder:)wait(for:timeout:)wait(for:timeout:enforceOrder:)waitForExpectations(timeout:handler:)XCWaitCompletionHandlerXCTestErrorXCTestError.CodeXCTestErrorDomain
Monitoring UI Interruptions
Handling UI InterruptionsaddUIInterruptionMonitor(withDescription:handler:)removeUIInterruptionMonitor(_:)