Swift Testing Migration: 10,000 Tests Modernized, 80% Faster CI Unlocked

Swift Testing migration - Swift Testing Migration: 10,000 Tests Modernized, 80% Faster CI Unlocked

Swift Testing Migration: A Leap Forward for Depop’s Testing Infrastructure

Depop has successfully navigated a significant modernization effort, migrating approximately 10,000 unit tests from the established XCTest framework to the newer Swift Testing. This strategic move, with partial assistance from coding agents, has not only streamlined their testing infrastructure but also dramatically reduced Continuous Integration (CI) runtime, unlocking substantial efficiency gains. The team recognized that embracing Swift Testing is pivotal as it represents the future direction of Apple Development.

The decision to undertake this extensive Swift Testing migration was driven by several compelling factors. Beyond aligning with Apple’s evolving roadmap, the team sought enhanced support for parallel test execution, seamless integration with Swift Concurrency, and access to advanced features. These include powerful capabilities like parameterized tests, nested test suites, and test traits, which offer greater flexibility and control over the testing process. A key objective was also to establish a standardized convention for testing across the entire codebase, addressing the previous lack of uniformity.

Architectural Advantages and Performance Gains with Swift Testing

A primary benefit realized from the Swift Testing migration is the significant improvement in test parallelization. Swift Testing executes tests in-process, leveraging Swift Concurrency’s cooperative thread pool. This architecture allows for efficient thread utilization, where a suspended test on an await operation frees up a thread for another test to utilize.

This in-process execution model proved highly advantageous for Depop’s CI environment. Early benchmarks indicated a remarkable reduction in execution time, with early benchmarks showing roughly an 80% runtime improvement when comparing XCTest without parallelization to Swift Testing with it. This substantial performance boost directly translates to faster feedback loops for developers and a more agile development cycle.

Engineering Trade-offs: AI Assistance vs. Manual Refinement

While AI agents played a supporting role, Depop opted for a predominantly manual, syntax-based migration approach. They utilized an open-source SwiftSyntax-based converter, swift-testing-revolutionary, which adheres to Apple’s official migration guidance. This choice was deliberate, aiming to avoid the subtle, unintended modifications that AI can sometimes introduce.

Even with strict instructions, AI-driven conversions sometimes veered into minor refactoring rather than pure syntactic transformation. While such changes might yield slightly improved tests, they significantly complicate the crucial code review process. To manage this, an AI agent was employed to orchestrate the entire migration workflow, from running conversion scripts and executing tests to automatically opening Pull Requests (PRs).

The agent was programmed to auto-approve PRs if test execution across 100 repetitions showed no errors or flakiness, and no changes were made to the core codebase. If tests failed, the agent would attempt to fix them, flagging the PR for human review. This hybrid approach balanced automation with essential human oversight, ensuring quality and maintainability.

Addressing Challenges and Future-Proofing with Swift Testing

The migration process was not without its challenges. Unexpected issues such as data races, tests passing locally but failing on CI, limitations of the conversion tool, and the overhead of PR reviews emerged. Data races were often resolved by assigning each test its own instance or by temporarily enforcing serialization using @Suite(.serialized).

CI-specific failures, particularly those related to UI tests running on secondary threads, were addressed by enforcing @MainActor isolation for all UI-related tests. It’s important to note that the automatic conversion process did not inherently leverage advanced Swift Testing features like parameterized tests, nested suites, and test traits. These advanced capabilities required a separate, manual refactoring effort to fully integrate.

While Depop utilized AI primarily as an orchestrator, other organizations have explored deeper AI integration. For instance, Sixt reportedly rewrote 7,000 unit tests using AI in a single afternoon for a minimal cost, by developing a custom conversion agent with approximately 1200 app-specific migration rules. This highlights the diverse strategies companies are employing to modernize their testing frameworks, much like how advancements in areas like electric vehicles are rapidly changing the automotive landscape, as seen with the 567-mile range of the new BMW i3 EV Deliveries. The successful Swift Testing migration at Depop underscores the benefits of adopting modern tooling for enhanced software quality and development velocity.

Source: InfoQ Software & Cloud Architecture