Fastlane scan: automate testing

ydcat
2 min readMay 1, 2022

When coding, everything can go wrong. A miss spell, lack dependencies, and more. As I writing my App, views doesn’t update accordingly. That makes up a lot of pain.

Then, tools come to rescue. In mobile App development, fastlane helps from testing to release. It including modules like scan, snapshot, pilot, match and so on. I suggest to under a progressive approach: adopt the tool in the toolbox one by one.

Approach to test

Before dive into usage introduction, I want to talk about an workable testing approach learned from Harry J.W. Percival who conduct a TDD development process. In his book Test-Driven Development with Python, the development test including following:

  • Functional test
  • Unit test

As the book focused on web development, the functional test means using selenium to test against the user story, the unit test means using Unittest or Pytest to test through model, view and other business logic. The basic logic is write user story first, then write functional test and make it fail. Then add code to pass that test. When begin to the business logic and model part code, write unit test first.

In iOS development, Apple provides similar concepts: UITest and Unit test. UITest could be analogue to functional test. Unite test is the same.

Fastlane scan Usage

After write the tests for the project, it’s time for the automation to takes parts. Before use fastlane, you need to install it. The easiest way is install it with Homebrew.

brew install fastlane

When first run it in a project, fastlane have a nice init command. It ask several questions and generate the configure.

fastlane init

In the fastlane folder, there are configures for each fastlane module. The Fastfile include all the lane for each task. The configure file for scan module is Sacnfile.

Ensure have following lines in the Fastfile.

platform: iOS do
desc "Run the tests"
lane :test do
scan(scheme: "YouAppTestScheme")
end
end

You could specify other parameters in Scanfile. The full list is in the official documentations.

To run the tests with command:

fastlane scan

Final words

We have adopt the test automation in the article. There are much more things to do as next steps. For example, trigger test run once we commit to the github repository by integrate with github actions or circle CI. The choice depends on what you familiar with.

--

--

ydcat

Indie developer. Creator of iOS App — Inspire Board. Coding in Python, Swift and JavaScript. Share thoughts and innovation. Attempting to learn and write more.