Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

swift-testing

БесплатноБез исполняемых скриптовНе проверен

WHEN writing, running, or diagnosing Swift Testing suites, including migrating XCTest tests to them and a crashing or non-reporting test target under…

mintuzот mintuz★ 38 звёзд на GitHub

Об этом скилле

Swift Testing

Author, modernise, and diagnose Swift Testing suites (import Testing), and migrate eligible XCTestCase suites cleanly.

Core Concepts and XCTest Boundary

  • Import Testing to unlock macros; tests are plain functions annotated with @Test.
  • Name tests freely without XCTest's test prefix: keep simple names lowerCamelCase (@Test func ignition()) and use raw identifiers in sentence case for multi-word behavioural descriptions (@Test func `Engine does not stall`()), or @Test("Display Name") for a custom navigator title.
  • #expect is the primary assertion; pass it a boolean expression.
  • Assert one behaviour per test function; split a test that checks unrelated behaviours.
  • Mark the test function async / throws when needed.
  • Swift Testing and XCTest run side by side in the same test target and even in the same file; a project that keeps XCTest targets or classes is a supported end state.
  • When a migration would be too large to review or bisect, convert an XCTest target in stages: give the staged order, migrate one class or small batch per stage, and keep the target green between stages (principle-sequence-verifiable-units).
  • What stays on XCTest: Swift Testing offers no UI-automation replacement for XCUITest (XCUIApplication) and no performance-measurement replacement for XCTest's measure { ... } baseline API. Keep measure { ... } performance tests on XCTest (other methods in the same XCTestCase can still migrate) and keep XCUIApplication UI test targets on XCTest (app:xcuitest). (Only when a user explicitly asks to migrate an XCUIAutomation bundle on Xcode 27+, read references/xcuiautomation-migration.md.)
  • Public API only: Never introduce underscore-prefixed symbols such as #_sourceLocation; use the full SourceLocation(fileID:filePath:line:column:) initialiser (leave pre-existing #_sourceLocation usages untouched during modernisation).

Assertions, Errors, and Issues

Expecting or Forbidding Throws

  • #expect(throws:) replaces XCTAssertThrowsError; #expect(throws: Never.self) (or try #require(throws: Never.self) when halting on failure) replaces XCTAssertNoThrow.
  • Whenever the error type is Equatable and the expected error case is known, always pin the specific error value (for example #expect(throws: FormatError.negativeAmount)) rather than the broader error type (FormatError.self) or (any Error).self.
  • Pass an error type (MyError.self) only when any case of that type is valid. Both #expect(throws:) (returns Error?) and try #require(throws:) (returns unwrapped Error, Xcode 16.3+) return the thrown error when you must assert on its properties. Never use the deprecated throws: matcher-closure overload.
@Test func `Rejects negative amount`() throws {
    #expect(throws: FormatError.negativeAmount) {
        try formatter.validate(-1)
    }

    #expect(throws: Never.self) {
        try formatter.prepare()
    }

    let error = try #require(throws: MyError.self) {
        try throwingFunction()
    }
    #expect(error.code == 42)
}

#require, #expect, and Issue.record

  • try #require(...) halts the test immediately on false or nil; use it to unwrap optionals instead of force-unwrapping (!), and whenever subsequent lines cannot run meaningfully after failure.
  • Prefer converting guard ... else { Issue.record(...); return } into try #require(...) and if !condition { Issue.record(...) } into #expect(condition) where not disruptive; drop redundant messages when the expression is self-explanatory.
  • Keep Issue.record("message") only when recording a non-fatal failure explicitly (add return when execution cannot continue).

Migrating XCTestCase to Swift Testing

Survey candidate files in one pass before editing; settle naming and struct vs final class choices up front, then migrate one XCTestCase class at a time.

Behavioural Differences and Traps

  • Foundation is not re-exported: XCTest re-exports Foundation, but Testing does not. When removing import XCTest, add import Foundation whenever the file uses URL, Data, Date, Locale, CharacterSet, ProcessInfo, or other Foundation types.
  • continueAfterFailure = false: When set inside a test method, convert every subsequent assertion in that method to try #require(...) and mark the test throws. When set in setUp() / setUpWithError(), it applies to all assertions in every test method of that class (plus setup/teardown): convert all of them to try #require(...). Never downgrade an existing try #require to #expect.
  • Suite type, setUp, and tearDown:
    • Prefer struct for suites. Swift Testing creates a fresh instance before each test, so replace setUp() / setUpWithError() stored properties with inline initialisers or init() (which may be async and throws; throwing in init fails the test). Mark methods mutating struct properti
Полный SKILL.md на GitHub

Установить swift-testing в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

Вложенные файлы

references/xcuiautomation-migration.md

FAQ

Что делает скилл swift-testing?

WHEN writing, running, or diagnosing Swift Testing suites, including migrating XCTest tests to them and a crashing or non-reporting test target under xcodebuild; NOT for authoring XCTest or XCUITest tests; returns macro-driven test patterns, the XCTest boundary, and the correct way to read xcodebuild results.

Как установить скилл swift-testing?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл swift-testing запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить swift-testing с