Swift Testing

Guidance for writing Swift tests with Apple’s modern Swift Testing framework instead of the older XCTest framework. It shows the framework’s test structure and assertion syntax.

In plain words
What is it for?
Use it to write tests, check values and collections, handle optional values, and verify that code throws expected errors.
Why use it?
It helps you use the correct Swift Testing patterns when creating or updating tests. This reduces confusion when moving away from XCTest.

Skill for Claude CodeCodex

Part of the super plugin — 6 skills, 5 commands, 6 agents, 4 MCP servers 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/onmyway133/claude-code-plugins/swift-testing
Any agent
npx skills add onmyway133/claude-code-plugins --skill swift-testing
Clone the repo
git clone --depth 1 https://github.com/onmyway133/claude-code-plugins

Made for: Claude Code, Codex.

Or install super, the plugin that ships this one along with the rest of its 6 skills, 5 commands, 6 agents, 4 MCP servers.

Per session 11 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 2,957 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 $0.00011 $0.02957
Opus 5 $0.00005 $0.01478
Sonnet 5 $0.00002 $0.00591
Haiku 4.5 $0.00001 $0.00296

Measured 3d ago against content hash c334019fc70c, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, 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 3d 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.

Origin

Copies of this mod

1 near-identical copy found in the catalogue:

plugins/super/skills/swift-testing/SKILL.md · 566 lines

How it starts

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

Swift Testing

You are a Swift testing expert using the modern Swift Testing framework (not XCTest). Apply these patterns when writing tests.

Framework Basics

Import and Structure

import Testing
@testable import MyApp

struct UserTests {
    @Test func createsUserWithValidEmail() {
        let user = User(email: "[email protected]")
        #expect(user.isValid)
    }
}

Key Differences from XCTest

XCTest Swift Testing
class with XCTestCase struct (preferred) or class
func testSomething() @Test func something()
XCTAssertEqual(a, b) #expect(a == b)
XCTAssertTrue(x) #expect(x)
XCTAssertNil(x) #expect(x == nil)
XCTAssertThrowsError #expect(throws:)
setUpWithError() init()
tearDown() deinit

Expectations

Basic Expectations

@Test func basicExpectations() {
    let value = 42

    // Boolean
    #expect(value > 0)
    #expect(value == 42)

    // Optionals
    let optional: String? = "hello"
    #expect(optional != nil)

    // Collections
    let array = [1, 2, 3]
    #expect(array.contains(2))
    #expect(array.count == 3)
}

Require (Unwrapping)

@Test func requireUnwrapping() throws {
    let optional: String? = "hello"

    // Unwrap or fail test
    let value = try #require(optional)
    #expect(value == "hello")

    // With custom message
    let user = try #require(fetchUser(), "User should exist")
    #expect(user.isActive)
}

Error Expectations

@Test func errorHandling() {
    // Expect any error
    #expect(throws: (any Error).self) {
        try riskyOperation()
    }

    // Expect specific error type
    #expect(throws: ValidationError.self) {
        try validate(email: "invalid")
    }

    // Expect specific error value
    #expect(throws: ValidationError.invalidEmail) {
        try validate(email: "")
    }
}

Test Organization

Suites (Grouping)

Read the full file on GitHub · 566 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. 3d ago First seen · 566 lines · 11 tokens per session scan A c334019fc70c

Subscribe to this mod's changes

Swift Testing is a skill published in the GitHub repository onmyway133/claude-code-plugins (5 stars, last pushed 7mo ago), licensed MIT. It adds 11 tokens to every session and 2,957 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-08-31.

Related

Other skills, from other repositories

golang-testing

Production-ready Golang tests — table-driven tests, testify suites and mocks, parallel tests, fuzzing, fixtures, goroutine leak detection with goleak, snapshot testing, code coverage, integration tests, idiomatic test naming. Use when writing or reviewing Go tests, choosing a testing approach, setting up Go test CI…

samber/cc-skills-golang · 115 tokens

golang-stretchr-testify

Comprehensive guide to stretchr/testify for Golang testing. Covers assert, require, mock, and suite packages in depth. Use when writing tests with testify, creating mocks, setting up test suites, or choosing between assert and require. Covers testify assertions, mock expectations, argument matchers, call verification…

samber/cc-skills-golang · 97 tokens

ios_developer

Comprehensive iOS development guidance covering SwiftUI, Swift Concurrency, Core Data, and Swift Testing.

onmyway133/skills · 24 tokens

sqlite_data

SQLiteData persistence library (Point-Free) - a fast SwiftData alternative using SQLite/GRDB. Use when working with SQLiteData, GRDB, type-safe SQL queries, @Table macro, @FetchAll/@FetchOne property wrappers, or migrating from SwiftData to SQLite-based persistence.

onmyway133/skills · 61 tokens

swift_testing

Modern Swift Testing framework patterns and best practices.

onmyway133/skills · 11 tokens

swift-testing-pro

Writes, reviews, and improves Swift Testing code using modern APIs and best practices. Use when reading, writing, or reviewing projects that use Swift Testing.

jacklandrin/OnlySwitch · 34 tokens