Skip to main content

Benefits of Swift Testing over XCTest


If you’ve been building apps in Swift for a while, you’ve probably spent some time writing tests with XCTest. It’s been the default testing framework on Apple platforms for years, and while it does the job, it often feels… a little clunky.


Now enter Swift Testing — a newer, more modern testing framework that’s part of the Swift open-source project. The difference is immediately noticeable. Writing tests with Swift Testing feels like writing Swift code, not fighting a bunch of boilerplate.

Here are some of the reasons why many developers are starting to prefer Swift Testing over XCTest:


1. The Syntax Just Flows Better

In XCTest, you’re constantly reaching for XCTAssertEqual, XCTAssertTrue, XCTAssertNil, and so on. Each one has its own function, and you need to remember which is which.

In Swift Testing, you simply use #expect with plain Swift expressions:

#expect(result == 42)

Compare that to:

XCTAssertEqual(result, 42)

Not a huge difference in one line, but when you multiply this across hundreds of tests, the Swift Testing style feels so much cleaner.


2. Failure Messages That Actually Help

One of the biggest frustrations with XCTest is its vague failure output. You’ll often see something like:

XCTAssertEqual failed: ("41") is not equal to ("42")

With Swift Testing, you get the exact expression and values spelled out in a way that makes debugging faster:

#expect(result == 42) failed – result was 41

It’s a small detail, but it makes a huge difference when you’re deep in test failures.


3. Async/Await Support That Feels Natural

XCTest bolted on async support later, so you still end up juggling expectation(description:) and wait(for:) in older tests.

Swift Testing was built with modern Swift in mind, so async tests just look like async functions. No hacks, no ceremony — just async and await like you’d expect.


4. No More Boilerplate

With XCTest, every test case lives inside a subclass of XCTestCase. It works, but it’s a holdover from Objective-C days.

Swift Testing lets you just write test functions without the ceremony:

@Test func additionWorks() {
    #expect(1 + 1 == 2)
}

That’s it. No subclassing, no overrides, no unnecessary setup.


5. It’s More than Just Apple

XCTest is tied tightly to Apple platforms. Swift Testing, on the other hand, is part of Swift’s open-source evolution. That means it’s designed to work not only in iOS and macOS apps but also on server-side Swift projects.

This makes it a much more future-friendly choice, especially if Swift keeps spreading beyond Apple’s ecosystem.


6. Community-Driven Future

Because Swift Testing lives in the open-source Swift project, it grows with community input. XCTest, by contrast, evolves mostly behind closed doors at Apple.

That means we’re likely to see Swift Testing improve rapidly in ways that reflect what developers actually want.


The Bottom Line

XCTest has served us well, but it carries a lot of baggage. Swift Testing feels lighter, more expressive, and better aligned with how we write Swift today.

  • Less boilerplate
  • More readable code
  • Better failure messages
  • Async-friendly out of the box
  • Open-source and future-proof

If you’ve ever groaned while typing out yet another XCTAssertEqual, give Swift Testing a try. You’ll probably never want to go back.


Popular posts from this blog

Animating label text update - choosing a better way

Recently I published a countdown app .  At one point of development - I have to show a timer on a UILabel which ticks on each seconds. As usual I started  setting text to a label object - self .timerLabel.text = someString Easy piece of cake right !?   But wait ... it won't take much user attention when timer ticks on every seconds. So I decided to make use of a simple animation while label gets text update. I found there are dozens of ways to animate a label. In this short article, I listed 3 best way you can animate text on a label. ( Spoiler Alert 👀- I decided to go with 3rd option)  1. Fade In - Fade out animation : CATransition class has got transition type `fade`. With timing function of CATransition - I was able to see the below result. let animation: CATransition = CATransition () animation.timingFunction = CAMediaTimingFunction (name: CAMediaTimingFunctionName .easeInEaseOut) animation.type = CATransitionType .fade animation.subtype = C...

Prevent Navigationbar or Tabbar overlapping Subview - solved for Card view

Recently, I started with a Card view added as a subview of UIView in a view-controller. When a view controller created along subviews, it tends to use entire screen bounds and also slips behind Tab bar or Navigation bar. In my current situation, it's second case. Casually new iOS developers will write a patch by additional value for coordinate y and subtracting bar height from its size. A lot of them posted in SO threads too : How to prevent UINavigationBar from covering top of view? View got hidden below UINavigationBar iOS 7 Navigation Bar covers some part of view at Top So, how I got solved ? self.edgesForExtendedLayout = [] This  will avoid all subviews in a view controller get behind any bars. Read full apple  documentation on here. Full Source code below :  //Simple view controller where its view layed-out as a card. class WidgetCardViewController : UIViewController { var containerView = UIView () //MARK:- View Controller Life Cyc...

UICollectionViewCell shows with wrong size on First time - Solved

We commonly use Collection view where its cell size calculated run time. The flow layout delegate is responsible to return individual cell sizes. BUT in most of the cases, delegate method `collectionView: layout sizeForItem:` expects cell size too early. Before generating actual cell size. extension YourViewController : UICollectionViewDelegateFlowLayout { func collectionView ( _ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { return CGSize (width: externalWidth, height: externalHeight) } } For instance, if a cell size depends on external view and its frame is not yet ready - results with wrong (or outdated) cell size. Typically happens for the first time view controller laid out all views. You can find similar queries in StackOverflow community : Collection view sizeForItemNotWorking UICollectionViewCell content wrong size on first load How to refresh UICollec...

Implementing autocompletion OTP field in iOS

Long waiting is over. !!  iOS 12 brings Autofill for OTP text field which is close to Android provided a decade back. Previously in iOS we used to toggle between OTP text screen and message inbox.  Which was hard to remember and time consuming resulting a bad user experience. Personally, I have been asked from the client/customer couple of times to implement autocompletion for OTP field and took me a lot of time to convey that it is not possible in iOS. Why Autofill was not possible previously?  We all know that Apple gives at most care for user privacy. When we see iOS architecture, each individual app is like a separate island. There is no inter-app bridge between apps (exception for Keychain and URLSchemes APIs which gives very limited scope). Thus we cannot read message content from inbox. Where to start Autofilling? First of all, the target SMS need to have the OTP Code with prefix string "Code" or "Passcode"on its message content. Beware of OTP c...

Static variable vs Class variable in Swift

How Static properties differs to usual properties ? Used to create type properties with either let or var. These are shared between all objects of a class.  During class loading time, a single memory location allocated for the property if we declared as static. Static property belongs to a class (or struct) Type rather than Instance of class (or struct). Hence it also called  Type Properties What if we declare "static var" ? Since it's a variable, we can change it in future even after initialised. When we change the value of the static variable property, that property is now changed in all future instances. What if we declare "static let" ? static let instance : Singleton = Singleton() Since it's constant, we cannot change once initialised. Its value will remain same even if we share among all the instance or object of a class or struct. Useful to adopt singleton pattern. How class variables differ static variables ? It dif...