posts

How to run Swift Tests Serially across files

Here's how I am running Swift Tests serially. Note, this is using Swift Testing.

I’m going to list the guide first and then why I needed to do this.

// NOTE

This is using Swift Testing

Guide

  1. Create a main test Suite and mark it as @Suite(.serialized)
import Testing

@Suite(.serialized)
struct MainTestSuite {
}
  1. Make an extension on the struct and put your other Suite in side it and also mark it as @Suite(.serialized)
extension MainTestSuite {
    @Suite(.serialized)
    struct SubTestSuiteA {
        @Test
        func testA() {
            #expect(true)
        }
    }
}

Repeat as you need to for all your suites

  1. Run your tests and your tests should ruin serially. In my testing, they are ran in alphabetical order.

Why I needed this

I am working on FetchKit, a user feedback system for my apps (and maybe yours), and I need to write tests for the repositories, which is what acceses the databases. Since I am testing reading and writing from databases, I want to just use one test database. At the end of each test, I clean up the databse and erase everything so if tests are running parallel the data the test expected to be there could be wiped. DEFINITELY DO NOT WANT THAT.

A lot of the examples I saw online showed:

import Testing

@Suite(.serialized)
struct MainTestSuite {
    @Suite(.serialized)
    struct SubTestSuiteA {
        @Test
        func testA() {
            #expect(true)
        }
    }
    @Suite(.serialized)
    struct SubTestSuiteB {
        @Test
        func testB() {
            #expect(true)
        }
    }
}

This is fine and ultimately nothing wrong with it, except for the file gets really massive, and I’m not a fan of that. I tried asking AI and well that was a bust, so I just tried writing the “sub” test suites in extensions and it worked.

Oct 16, 2025 ship-a-tonswiftcamp notes
Camp Notes's First Paywall Experiment
Starting my first paywalll experiment for Camp Notes.
Oct 13, 2025 ship-a-tonswiftcamp notes
Camp Notes Won a OneSignal Boost Award at Shipaton
Camp Notes placed 5th in the OneSignal Boost Award category at RevenueCat's Shipaton hackathon. This post covers what Shipaton is, why I entered, how I implemented OneSignal for notifications and emails, and what I learned from competing against over 800 entries.
Sep 12, 2025 ship-a-tonswiftcamp notes
Camp Notes v1.0.0 is now shipping
Camp Notes was approved last week and has been in the App Store for about a week.