Swift Testing

Expressive tests written with macros, made for Swift from the start.

Introduced
2024
WWDC24
Kind
Framework
Runs on
Xcode 16 or later
Get it from
Included with Xcode
iOS
iPadOS
Mac Catalyst
macOS
tvOS
visionOS
watchOS

Overview

Mark a function with @Test and check results with #expect. When something fails, you see the actual values involved, not just “assertion failed”.

Tests can take arguments to run once per input, carry tags and traits, and run in parallel by default. It lives alongside XCTest, so you can adopt it one file at a time.

@Test

Any function can be a test: no subclass, no test prefix, async and throwing allowed.

#expect and #require

One macro for checks that captures the values involved when something fails.

Parameterized tests

Pass a collection of arguments and the same test runs once per input.

Traits and tags

Disable, time-limit, serialize or group tests with a short annotation.

PriceTests.swift
import Testing @Test("Discounts never go below zero", arguments: [0, 10, 50, 100]) func discount(percent: Int) { let price = Price(amount: 20) let result = price.applying(discount: percent) #expect(result.amount >= 0) }

History

How it grew up.

2024

Introduced

Ships with Xcode 16 alongside XCTest.

2025

Exit tests and attachments

Test code that crashes on purpose, and attach files to results.

2026

XCTest interop

XCTest assertions and #expect work across both frameworks.