๐Ÿ‘ฉโ€๐Ÿ”ฌ Testing Swift CLI Tools with GitHub Actions ๐Ÿงช

CI/CD
GitHub Actions
Tests
October 6, 2025
Sponsored

Forget about Ruby and Fastlane installation issues!

Discover Codemagic CLI Tools - the free, open-source Fastlane alternative for automating iOS builds, code signing and publishing.

This message is brought to you by a sponsor who helps keep this content free for everyone. If you have a moment, check them out - your support means a lot!

Welcome to issue #59 of the iOS Coffee Break Newsletter ๐Ÿ“ฌ.

Hello all ๐Ÿ‘‹! I know, I know! The past few weeks have been busy for me, and I haven't been able to write as often as I'd hoped. But this week, we are back on track!

I also want to take this chance to let you know that the newsletter will be shifting from a weekly schedule to a more occasional, likely bi-weekly or monthly. I have some new opportunities coming up, which means I'll have less time to focus to writing. That said, let's dive right into this week's topic!

If you have been keeping up with the newsletter, you probably know I have been working on a command-line tool that generates dummy data ๐Ÿ› . In a previous edition, I explained how I automated its release process using GitHub Actions.

As part of my learning on GitHub Actions, I recently set up a workflow to run tests for the CLI tool. This week, I would like to walk you through that process and what I learned!

The Plan

In this edition, my plan was to set up a GitHub Actions workflow to run tests for my command-line tool. Here is what I wanted the workflow to do:

  • Trigger automatically on any push or pull request to the repository main branch.
  • Run Tests on a macOS environment.

Setting Up the Test Workflow

First, we need to add a workflow file in the .github/workflows directory. If that folder doesn't exist yet, go ahead and create it.

$ mkdir -p .github/workflows
$ touch .github/workflows/test.yml

Writing the GitHub Workflow

The next step is to define our workflow:

name: Run Tests
 
on:
  pull_request:
    branches:
      - main
  push:
    branches:
      - main
 
jobs:
  macos-test:
    name: Test on macOS
    runs-on: macOS-15
    timeout-minutes: 30
    env:
      DEVELOPER_DIR: /Applications/Xcode_16.2.app
    steps:
      - name: Checkout
        uses: actions/checkout@v4
      - name: Run unit tests on macOS for Swift Package
        run: |
          set -o pipefail && xcodebuild -scheme SwiftDummyGen-Package \
            -destination "platform=macOS" test | xcpretty

Here is a quick overview of what the workflow does:

  • It is triggered whenever code is pushed to the main branch or a pull request is opened targeting it.
  • The first step uses the checkout action to pull the latest version of the code from the repository so it can be tested.
  • We use xcodebuild to execute the tests. The -scheme option tells it which scheme to build and test while the -destination flag sets the target environment. In this case, macOS.
  • In the end, we pipe the output through xcpretty to make the results cleaner and easier to read.

๐Ÿค Wrapping Up

Using GitHub Actions to automate iOS testing simplifies our workflow by identifying issues early and frequently. This issue outlines a simple configuration that can serve as a foundation for more advanced setups, like testing across different simulators or incorporating UI tests.

Have any feedback, suggestions, or ideas to share? Feel free to reach out to me on Twitter.

tiagohenriques avatar

Thank you for reading this issue!

I truly appreciate your support. If you have been enjoying the content and want to stay in touch, feel free to connect with me on your favorite social platform: