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★ 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
Testingto unlock macros; tests are plain functions annotated with@Test. - Name tests freely without XCTest's
testprefix: keep simple nameslowerCamelCase(@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. #expectis 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/throwswhen 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'smeasure { ... }baseline API. Keepmeasure { ... }performance tests on XCTest (other methods in the sameXCTestCasecan still migrate) and keepXCUIApplicationUI test targets on XCTest (app:xcuitest). (Only when a user explicitly asks to migrate anXCUIAutomationbundle on Xcode 27+, readreferences/xcuiautomation-migration.md.) - Public API only: Never introduce underscore-prefixed symbols such as
#_sourceLocation; use the fullSourceLocation(fileID:filePath:line:column:)initialiser (leave pre-existing#_sourceLocationusages untouched during modernisation).
Assertions, Errors, and Issues
Expecting or Forbidding Throws
#expect(throws:)replacesXCTAssertThrowsError;#expect(throws: Never.self)(ortry #require(throws: Never.self)when halting on failure) replacesXCTAssertNoThrow.- Whenever the error type is
Equatableand 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:)(returnsError?) andtry #require(throws:)(returns unwrappedError, Xcode 16.3+) return the thrown error when you must assert on its properties. Never use the deprecatedthrows: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 onfalseornil; 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 }intotry #require(...)andif !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 (addreturnwhen 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
Foundationis not re-exported:XCTestre-exportsFoundation, butTestingdoes not. When removingimport XCTest, addimport Foundationwhenever the file usesURL,Data,Date,Locale,CharacterSet,ProcessInfo, or other Foundation types.continueAfterFailure = false: When set inside a test method, convert every subsequent assertion in that method totry #require(...)and mark the testthrows. When set insetUp()/setUpWithError(), it applies to all assertions in every test method of that class (plus setup/teardown): convert all of them totry #require(...). Never downgrade an existingtry #requireto#expect.- Suite type,
setUp, andtearDown:- Prefer
structfor suites. Swift Testing creates a fresh instance before each test, so replacesetUp()/setUpWithError()stored properties with inline initialisers orinit()(which may beasyncandthrows; throwing ininitfails the test). Mark methods mutatingstructproperti
- Prefer
Установить swift-testing в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
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), без исполняемых скриптов.
Похожие скиллы
doc-coauthoring
Guide users through a structured workflow for co-authoring documentation. Use when user wants to write documentation, proposals, technical specs, decision…
от Anthropicacademy-guide
Stop and check this skill before finishing any reply to a question about how to use Claude or a Claude product — it recommends matching courses, tutorials…
от Anthropicinternal-comms
A set of resources to help me write all kinds of internal communications, using the formats that my company likes to use. Claude should use this skill…
от Anthropicskill-development
This skill should be used when the user wants to "create a skill", "add a skill to plugin", "write a new skill", "improve skill description", "organize skill…
от Anthropic