iOS Automated Testing with Fastlane ๐
If you want to automatically test your iOS applications in your Continuous Integration (CI) service of choice, Fastlane is the tool for you.
You no longer need to browse the Internet in search of a script or create your own. It usually becomes extensive, less scalable and harder for someone else to quickly adjust it to new needs.
This article introduces Fastlane and explains how to use the Scan tool in order to achieve Automated Testing.
Due to the length of the article it is split into two parts that can be followed independent of each other:
Fastlane
Fastlane, currently maintained by Google, is a Continuous Delivery (CD) tool that comes with a wide set of base tools, each with its own purpose, being testing, deployment, incrementing project versions and many others. These will probably be more than enough for you, but you can also create or integrate plugins from the community.
In the old days, you had to create your own solution or fetch multiple scripts from other people in order to be able to automate the process of building and deploying your projects. This is why Fastlane is so great, you will find everything you need in one place, with a community to help you if necessary and a simple and embracing configuration that fits your needs.
If you are worried about pairing Fastlane with your CI service of choice, it already has tools to support the most popular ones: Travis CI, Bitrise, Circle CI and Jenkins.
Installing Xcode command line tools:
xcode-select --install
Installing Fastlane:
[sudo] gem install fastlaneORbrew cask install fastlane
NOTE: Make sure you have your terminal locale set to en_US.UTF-8
. You can also add these to your .bash_profile
file or to your terminal configuration.
export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8
export LANGUAGE=en_US.UTF-8
NOTE: Make sure you have the correct Xcode selected
xcode-select -p
Setup Fastlane
fastlane init
As you can see, Fastlane already comes with three base setups to facilitate the deployment automation, but this article only focus on automatically testing your applications, we will choose 4. Manual setup
.
Fastlane will create a folder fastlane
with an Appfile
and a Fastfile
which we can ignore for now.
For a more detailed tutorial or if you are having any problems following the guide so far, you can follow Fastlane setup guide.
Notes: Sample Project ๐
Notes is an iOS application that allows the user to add, remove and change notes. This project is used to illustrate how to do automated testing using Fastlane together with Travis CI.
The entire project is available on GitHub, for you to consult and use as you please.
Testing using Scan (from Fastlane)
Now we have to prepare the application for testing using Fastlane, more specifically, the Scan tool.
fastlane scan init
This command will create a Scanfile
under your fastlane
folder. This is the file you need to configure in order to properly test your application.
Simple configuration (for all the available configurations visit section Parameters):
This simple configuration tests the scheme Notes
, for the specified devices (iPhone 8), prints the results and sends a notification to Slack.
fastlane scan
NOTE: To get a slack_url
you need to add the app Incoming WebHooks
to your Slack and use the provided url, as simples as that!
Automated Testing using Travis CI
All you need to do now is add the scan command to your CI service script and you are good to go.
In the future, you donโt need to modify the CI script to cope with testing related changes, you can do almost everything under the Scanfile
.