Command Palette

Search for a command to run...

Назад к скиллам
скилл № 53631

converting-xctest-to-swift-testing

Convert an XCTest file to Swift Testing framework. Use when asked to "convert to Swift Testing", "migrate XCTest", "convert test file", "xctest to swift…

БесплатноБез исполняемых скриптов
bitwardenот bitwarden★ 748 звёзд на GitHub

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

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

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

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

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

Converting XCTest to Swift Testing

Use this skill to convert an existing XCTest file to the Swift Testing framework following Bitwarden iOS patterns.

Before You Start — Is This File Convertible?

Do NOT convert the following; leave them in XCTest:

Pattern Why
ViewInspector tests imports ViewInspector; requires XCTest infrastructure
Snapshot tests Functions named disabletest_*, uses assertSnapshot or SnapshotTesting; depends on BitwardenTestCase
UI automation tests Uses XCUIApplication
Performance tests Uses measure { ... } or XCTMetric
Objective-C tests Cannot use Swift Testing
Tests asserting on alert display Uses coordinator.alertShown; alert presentation requires UI.animated = false, which BitwardenTestCase.setUp() sets
Tests asserting on loading overlay display Uses coordinator.loadingOverlaysShown; same dependency on UI.animated = false

Stop and flag the issue before proceeding.

Step 1: Read the File

Read the entire test file first. Understand:

  • What type is under test (processor, coordinator, service, etc.)
  • Whether any methods have @MainActor (and which)
  • Whether any tests use addTeardownBlock
  • Any non-mechanical patterns that may need judgment calls

Step 2: Transform the File Header

Imports

Replace import XCTest with import Testing. Keep all other imports unchanged:

// Before:
import XCTest
@testable import BitwardenShared

// After:
import Testing
@testable import BitwardenShared

XCTest implicitly re-exports Foundation, so removing it can cause missing-symbol build errors if the file uses Foundation types directly. If the build fails after conversion, add import Foundation.

Class → Struct

Before After
class FooTests: BitwardenTestCase { struct FooTests {
final class FooTests: BitwardenTestCase { struct FooTests {

@MainActor placement

If test methods had @MainActor (processor tests, coordinator tests), move it to the struct declaration:

// Before: @MainActor on individual methods
// After:
@MainActor
struct FooProcessorTests {

Service tests typically do not need @MainActor — do NOT add it unless the service dispatches to main.

Step 3: Convert Properties

Change force-unwrapped var properties (those ending in !) to let non-optionals:

// Before:
var coordinator: MockCoordinator<FooRoute, FooEvent>!
var errorReporter: MockErrorReporter!
var subject: FooProcessor!

// After:
let coordinator: MockCoordinator<FooRoute, FooEvent>
let errorReporter: MockErrorReporter
let subject: FooProcessor

services property: Remove it if it is only used inside setUp() to construct the subject — it does not need to be a stored property in Swift Testing. Keep it as let services: MockServiceContainer if test methods reference it directly for assertions.

Step 4: Convert Setup, Teardown, and State Lifecycle

Swift Testing replaces setUpWithError and tearDownWithError with a more natural, type-safe lifecycle using init() and deinit.

The Core Concept: A fresh, new instance of the test suite (struct or class) is created for each test function it contains. This is the cornerstone of test isolation, guaranteeing that state from one test cannot leak into another.

Method Replaces... Behavior
init() setUpWithError() The initializer for your suite. Put all setup code here. It can be async and throws.
deinit tearDownWithError() The deinitializer. Put cleanup code here. It runs automatically after each test. Note: deinit is only available on class or actor suite types, not structs. This is a common reason to choose a class for your suite.

setUp() → init()

Move all setup code into init(), removing the super.setUp() call:

// Before:
override func setUp() {
    super.setUp()

    coordinator = MockCoordinator()
    errorReporter = MockErrorReporter()
    subject = FooProcessor(
        coordinator: coordinator.asAnyCoordinator(),
        services: ServiceContainer.withMocks(errorReporter: errorReporter),
        state: FooState(),
    )
}

// After:
init() {
    coordinator = MockCoordinator()
    errorReporter = MockErrorReporter()
    subject = FooProcessor(
        coordinator: coordinator.asAnyCoordinator(),
        services: ServiceContainer.withMocks(errorReporter: errorReporter),
        state: FooState(),
    )
}

tearDown() → delete

Remove the entire tearDown() override. Swift Testing creates a fresh struct instance for every test — all properties are discarded automatically. No nilling out is needed.

addTeardownBlock { ... }

  • If the block just nils out properties: delete it (struct isolation handles this).
  • If the block cleans up external resources (e.g., temp files, keychain entries): convert to `dei
Полный SKILL.md на GitHub

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

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

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

FAQ

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

Convert an XCTest file to Swift Testing framework. Use when asked to "convert to Swift Testing", "migrate XCTest", "convert test file", "xctest to swift testing", "migrate tests to Swift Testing", or when explicitly asked to convert existing XCTest-based tests.

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

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

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

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

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

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