Contents

Testing

Develop and run tests to detect logic failures, UI problems, and performance regressions.

Overview

An important part of software development is testing your code. To catch issues early and deliver the highest quality products, use the frameworks and features Xcode provides to develop tests, understand code coverage, and evaluate your test results.

Xcode 16 and later includes Swift Testing, a new testing framework you can use to write unit tests that takes advantage of the powerful and expressive language capabilities of Swift with output that is expressive and actionable. Xcode continues to include XCTest to facilitate writing UI tests that control your app’s UI using XCUIAutomation. A good testing strategy combines multiple types of tests, to maximize the benefits of each.

Aim for a “pyramid” distribution of tests, as shown in the figure below. Include a large number of fast, well-isolated unit tests to cover your app’s logic, a smaller number of integration tests to demonstrate that smaller parts connect together properly, and UI tests to assert the correct behavior of common use cases.

[Image]

UI tests are the ultimate indicator your app works the way you expect, but they take longer to run than other kinds of tests. There are various app variables that can introduce a failure in the same UI test. The test pyramid balances high-fidelity tests that demonstrate that people can complete their tasks, with tightly-focused tests that give you fast feedback about the correctness of your app’s logic and the impact of changes you make.

In addition to the test pyramid, write performance tests to provide regression coverage of performance-critical regions of code. To learn about the process of identifying performance-critical code, see Improving your app’s performance.

Topics

Test development

Execution and results

Performance tests

Location

StoreKit

See Also

Tuning and debugging