Engineering

26 February, 2018

iOS Automated Testing with Fastlane 🚀

If you want to implement iOS automated testing in your Continuous Integration (CI) service of choice, Fastlane is the tool for you.

André Silva

CEO

iOS Automated Testing with Fastlane -  Coletiv Blog

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.

Installation

Installing Xcode command line tools:

xcode-select --install

Installing Fastlane:

[sudo] gem install fastlane OR brew 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

Fastlane base setup options Fastlane base setup options

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):

# For more information about this configuration visit # https://docs.fastlane.tools/actions/scan/#scanfile # In general, you can use the options available # fastlane scan --help scheme "Notes" devices ["iPhone 8"] # Slack - uncomment the following lines for Slack Notifications # slack_url "your_slack_url" # slack_channel "your_slack_channel" clean true

This simple configuration tests the scheme Notes, for the specified devices (iPhone 8), prints the results and sends a notification to Slack.

fastlane scan

Fastlane test results Fastlane test results

Fastlane Slack Notification Fastlane Slack Notification

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.

# Configuration language: objective-c osx_image: xcode9.2 xcode_sdk: iphonesimulator11.0 # Continuous Integration Script # fastlane scan - runs the application tests script: - fastlane scan

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.

iOS

Software Development

Continuous Integration

Fastlane

Automated Testing

Travis CI

Join our newsletter

Be part of our community and stay up to date with the latest blog posts.

Subscribe

Join our newsletter

Be part of our community and stay up to date with the latest blog posts.

Subscribe

You might also like...

Go back to blogNext
How to support a list of uploads as input with Absinthe GraphQL

Engineering

26 July, 2022

How to support a list of uploads as input with Absinthe GraphQL

As you might guess, in our day-to-day, we write GraphQL queries and mutations for Phoenix applications using Absinthe to be able to create, read, update and delete records.

Nuno Marinho

Software Engineer

Flutter Navigator 2.0 Made Easy with Auto Router - Coletiv Blog

Engineering

04 January, 2022

Flutter Navigator 2.0 Made Easy with Auto Router

If you are a Flutter developer you might have heard about or even tried the “new” way of navigating with Navigator 2.0, which might be one of the most controversial APIs I have seen.

António Valente

Software Engineer

Enabling PostgreSQL cron jobs on AWS RDS - Coletiv Blog

Engineering

04 November, 2021

Enabling PostgreSQL cron jobs on AWS RDS

A database cron job is a process for scheduling a procedure or command on your database to automate repetitive tasks. By default, cron jobs are disabled on PostgreSQL instances. Here is how you can enable them on Amazon Web Services (AWS) RDS console.

Nuno Marinho

Software Engineer

Go back to blogNext