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.
Exercism aims to provide opportunity for people of all backgrounds by helping them develop their programming skills through practice and mentorship. We provide thousands of exercises spread across over 50 language tracks, and offer both automated and human mentoring.
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.
branches: [ main ]
# 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 🚀🚀🚀