Testing your iOS application with Fastlane and Github Actions.

Learn how to create a simple CI to test your Swift code.

Guilherme Tavares Shimamoto
Academy@EldoradoCPS
2 min readAug 28, 2020

--

Isaac Asimov, “Robbie”

Hello there! During the quarantine I started creating a Swift framework to validate Brazilian documents. In this post, I want to share with you some of the things that I've learned during this process, basically how to create a simple CI to test your Swift code.

If you want to know a little bit more about CocoaPods frameworks, I suggest reading the CocoaPods guides. And to create a framework, I recommend following this tutorial.

Without further ado, here is DocumentsValidator. In this project you can see the usage of the technologies that I'll be discussing in the next lines.

How to run the tests?

After the work was done with the code and unit tests, Fastlane was integrated in the project. Fastlane is an automation tool, that helps handling some tasks, such as generating screenshots, dealing with code signing, deployment and WOW *running unit tests*. To install Fastlane in your project just follow this tutorial.

After integrating with Fastlane, you can edit your Fastfile to create your lanes and automate your tasks! This is my simple Fastfile for running the unit tests:

The project now has an automation tool, let's see how to create the CI with Github Actions.

Time to action!

Github Actions is a powerful tool from Github to automate your workflow and, as your project is public, using it is totally free. What I intended to do was to make Github Actions execute the test lane that we'd created.

I recommend following this tutorial to create and understand the configuration file. Finally, this is how my configuration file looks like:

With this configuration, every time that a PR is open or a merge is done, in the master and development branches, Github will run the unit tests of the project. In that way, (if you test your code) we can avoid putting bugs in our main branches.

As a result, you can check every workflow in the "Actions" session of your Github project. Inside each workflow you can se the details (logs and results) from our jobs.

I hope you all have enjoyed this post, I really recommend applying this technologies to your personal projects. That's all folks!

--

--