converting-xctest-to-swift-testing

Convert XCTest test files to the Swift Testing framework following Bitwarden iOS patterns.

680|154|Updated Jul 14, 2023
One-click install
npx skills add https://github.com/bitwarden/ios --skill converting-xctest-to-swift-testing
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: converting-xctest-to-swift-testing
Source: https://github.com/bitwarden/ios/tree/main/.claude/skills/converting-xctest-to-swift-testing
Command: npx skills add https://github.com/bitwarden/ios --skill converting-xctest-to-swift-testing

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Migrating iOS test suites from XCTest to Swift Testing involves many mechanical and judgment-based transformations—imports, class-to-struct conversion, lifecycle changes, assertion rewrites, and parameterized tests—that are error-prone when done by hand. This Skill provides a step-by-step conversion procedure with Bitwarden-specific conventions.

Core Features & Use Cases

  • Guided Conversion Workflow: Nine ordered steps covering imports, struct conversion, init/deinit lifecycle, @Test annotations, DocC comments, and assertion replacement with #expect and #require.
  • Convertibility Screening: Identifies files that must stay in XCTest, such as ViewInspector tests, snapshot tests, UI automation, performance tests, and alert/loading-overlay assertions.
  • Parameterized Test Migration: Consolidates repetitive XCTest methods into @Test(arguments:) parameterized tests using zip patterns.
  • Use Case: Given a Bitwarden iOS processor test file written with XCTestCase, convert it into a Swift Testing struct with @MainActor placement, let-initialized mocks, DocC-documented @Test functions, and #expect/#require assertions, then verify with grep checks and a build.

Quick Start

Convert the XCTest file FooProcessorTests.swift to Swift Testing following the conversion steps in this skill.

Frequently Asked Questions about converting-xctest-to-swift-testing

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I convert XCTest tests to Swift Testing?▼

Replace import XCTest with import Testing, change the XCTestCase class to a struct, move setUp logic into init(), annotate test methods with @Test, and replace XCTAssert calls with #expect or #require macros. Remove tearDown since Swift Testing creates a fresh instance per test.

What is the Swift Testing equivalent of XCTAssertEqual and XCTUnwrap?▼

XCTAssertEqual(a, b) becomes #expect(a == b) using standard Swift operators. XCTUnwrap becomes try #require(a), which both checks for nil and unwraps the optional, aborting the test if the value is nil.

Which XCTest files cannot be converted to Swift Testing?▼

Do not convert ViewInspector tests, snapshot tests using assertSnapshot, UI automation tests with XCUIApplication, performance tests using measure or XCTMetric, Objective-C tests, or tests asserting on alert or loading overlay display that depend on BitwardenTestCase setup.

How do parameterized tests work in Swift Testing?▼

Use @Test(arguments:) with a collection of inputs, or zip(inputs, expectedOutputs) to pair inputs with expected results. Each argument set runs as an independent test with individually reported failures, replacing repetitive single-case test methods.

Why does my converted Swift Testing file fail to build?▼

XCTest implicitly re-exports Foundation, so removing import XCTest can cause missing-symbol errors if the file uses Foundation types directly. Add import Foundation explicitly and rerun the build to resolve these errors.