Published in


Swift Unit Test Automation

Let’s say you have multiple packages with unit tests. We don’t like to test these packages one by one. So how can we test it collectively and see the results?
We encountered such a case in Kodluyoruz & Trendyol iOS Bootcamp 🚀. We are solving algorithm questions in exercism.io. We tried to find a solution so that the assistants could check whether it passed the tests more easily.

We think of github actions. Here we could run tests for each package by running terminal commands. But instead of the terminal outputs of the tests, it would be better if we could only see what percentage of the tests we passed and which package failed the test. So I had to write a script that can be run in github action.

I coded a python script that writes terminal level scripts and tests for each package. Script handle the terminal outputs, it shows;

  • 🚀 Total swift packages count,
  • 🚀 Total unit test count,
  • 🚀 Compiling errors,
  • 🚀 Failed tests count,
  • 🚀 Which packages encountered errors,
  • 🚀 Average test success results.

So how do we run this script in our repository?

We need to set up a workflow in actions section on your repository.

Github provide a standard main.yml file. We change main.yml file like this.

name: CI
branches: [ main ]

runs-on: ubuntu-latest
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2
# You can run script like this
- name: Run Script
run: python3 .script/main.py

Great. Where is our main.py? Here, you can use from this repository.
Also, if your package folders are not directly under your repo, you need to give which folder it is under as a parameter. If your package folders under “myFolder”. You need to do like this.

- name: Run Script
run: python3 .script/main.py myFolder1

When you push packages, output results will be like these.

If your tests has any fail or compiling error.

The convenience of automating things is really great. This has been a very good experience for me.

Thank you for sharing this experience. See you 🚀🚀🚀



Kodluyoruz’da amacımız Türkiye’de dünya çapında yazılımcılar yetiştirerek teknoloji sektörünün yetenek açığını kapatmak. Bu blogda ise hem şirketlerin yazılım ekipleriyle ilgili sorularını yanıtlıyor, hem geleceğin yazılımcılarıyla bildiklerimizi paylaşıyoruz.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store