swift-testing

swift-testing is a skill for Claude Code from markdavidgan/apple-dev-skills. It costs 16 tokens per session (1,801 once invoked), scanned A, original, MIT.

A modern way to write tests in Swift using Apple's Swift Testing framework. Unit tests check small pieces of program logic, while integration tests check how several pieces work together; interface tests still use XCTest.

In plain words
What is it for?
Use it to write unit and integration tests with `@Test`, `#expect`, and `#require` in Swift projects.
Why use it?
It helps developers test application logic with the newer framework without requiring every existing XCTest to be migrated at once.

Skill for Claude Code

Written for Claude Code: shipped in a Claude Code plugin.

Part of the apple-dev-skills plugin — 62 skills, 25 commands, 7 agents shipped together

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/markdavidgan/apple-dev-skills/swift-testing
Any agent
npx skills add markdavidgan/apple-dev-skills --skill swift-testing
Clone the repo
git clone --depth 1 https://github.com/markdavidgan/apple-dev-skills

Made for: Claude Code.

Or install apple-dev-skills, the plugin that ships this one along with the rest of its 62 skills, 25 commands, 7 agents.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for swift-testing

README.md
[![agentmods](https://agentmods.dev/badge/skills/markdavidgan/apple-dev-skills/swift-testing.svg)](https://agentmods.dev/skills/markdavidgan/apple-dev-skills/swift-testing)
Your own site
<a href="https://agentmods.dev/skills/markdavidgan/apple-dev-skills/swift-testing"><img src="https://agentmods.dev/badge/skills/markdavidgan/apple-dev-skills/swift-testing.svg" alt="Measured on agentmods" height="20"></a>
Per session 16 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,801 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00016 $0.01801
Opus 5 $0.00008 $0.00901
Sonnet 5 $0.00003 $0.00360
Haiku 4.5 $0.00002 $0.00180

Measured 2d ago against content hash 29197b52de16, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-05, from the pricing page.

Security

Grade A, and why

swift-testing scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

platforms/claude/skills/swift-testing/SKILL.md · 185 lines

How it starts

The opening of the file, as written. The whole thing — 185 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Swift Testing

Author tests with the modern Swift Testing framework (import Testing, Xcode 16+/Swift 6). It coexists with XCTest in the same target — migrate incrementally. For the test harness, CI wiring, SwiftData in-memory setup, and UI/performance testing, see ios-test; this skill is the authoring model.

Pick the right tool. Swift Testing covers unit/integration/logic tests. UI tests (XCUIApplication) and XCTMetric performance tests still use XCTest — Swift Testing does not replace them. You can keep both in one project.


The shape of a test

import Testing
@testable import MyApp

@Test func timerStartsAtConfiguredDuration() {
    let timer = FocusTimer(minutes: 25)
    #expect(timer.remaining == .seconds(25 * 60))
}
  • No XCTest subclass, no test prefix, no XCTAssert. A free function (or method) annotated @Test.
  • #expect(...) records a failure but continues. It captures the full expression, so #expect(a == b) reports the actual values of a and b — no need for XCTAssertEqual.
  • Give tests descriptive names: @Test("Remaining time is clamped to zero").

#require — stop on failure / safe unwrap

@Test func decodesUser() throws {
    let data = try #require(Self.fixture)         // unwraps Optional or throws → test stops
    let user = try JSONDecoder().decode(User.self, from: data)
    #expect(user.name == "Ada")
}

#require is the hard assert: if it fails the test stops (like a guard). Use it when continuing would crash or cascade. try #require(optional) is the idiomatic non-force unwrap.


Async, throwing, and errors

@Test func loadsRemoteProfile() async throws {
    let profile = try await client.fetchProfile(id: 42)   // just use async/await
    #expect(profile.id == 42)
}

// Asserting a specific error is thrown
@Test func rejectsEmptyName() {
    #expect(throws: ValidationError.emptyName) {
        try Validator.validate(name: "")
    }
}

// Any error / error of a type
#expect(throws: (any Error).self) { try risky() }
#expect(throws: ValidationError.self) { try validate() }
#expect(throws: Never.self) { try shouldNotThrow() }   // asserts NO throw

Read the full file on GitHub · 185 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen · 185 lines · 16 tokens per session scan A 29197b52de16

Subscribe to this mod's changes

swift-testing is a skill published in the GitHub repository markdavidgan/apple-dev-skills (5 stars, last pushed 6d ago), licensed MIT. It adds 16 tokens to every session and 1,801 once invoked, about $0.0001 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-09-03.

Related

Other skills, from other repositories