Learnings About Swift Testing
Article Summary
Apple's Swift Testing framework is here, and Mercari's iOS team thinks it's a game-changer. If you're still on XCTest, here's what you're missing.
Cyan from Mercari's Mercoin iOS team shares hands-on learnings from adopting Swift Testing, Apple's new unit testing framework introduced at WWDC24. This is a practical guide to understanding what makes it superior to XCTest and how to start using it.
Key Takeaways
- Replace dozens of XCAssert functions with a single #expect macro
- Traits system enables conditional tests, time limits, and better organization
- Parameterized testing eliminates repetitive test code across multiple scenarios
- Suites support stored properties and init/deinit for cleaner setup logic
- Swift Testing runs alongside XCTest for gradual migration
Critical Insight
Swift Testing simplifies iOS unit testing with a single assertion macro, powerful traits for test customization, and parameterized tests that eliminate code duplication.