Software Engineer Desk

How to Send Test Results to Slack Channel Via Fastlane

Problem

Wasting time when running tests.

Solution

Automating tests with Fastlane. It sends test results to a Slack channel to monitorize.


Every developer wishes to write bug-free code. They analyze cases, think about edge cases, write tests, etc. The part that we are interested in on all of these is test.


Fastlane

Fastlane is an open-source platform aimed at simplifying Android and iOS deployment. Fastlane lets you automate every aspect of your development and release workflow.(source: https://fastlane.tools)

Fastlane is a quite useful tool for mobile developers. It handles running tests, uploading screenshots, signing code, distributing via Testflight, even publishing to the App Store.

In this article, we are going to see how to run tests via Fastlane and send the test results to a Slack channel.


First of all, we create a new project in which tests are included. Then run tests and make sure they work well.

Open the terminal and go to the path of the iOS project. Type sudo fastlane init and run. Then, choose Manual Setup. After the installation, we see the fastlane folder created.


Slack

Slack is a communication platform for teams. It has useful integrations with other tools. One of the beneficial services of Slack is that webhooks. Webhooks help to take action on the related channel.

First of all, we create a Slack workspace(if we don’t have any) and create a channel named fastlane(or whatever you want).

We go to the api.slack.com via a web browser. Click Your Apps on the top-right. Create a new app(same as a bot) then go back to the api.slack.com/apps. We click the app name then click the Incoming Webhooks under the Feature section on the left. Set Activate Incoming Webhooks on before creating a webhook. At the bottom of the page, we see webhooks with Add New Webhook to Workspace button. Click it and add the app to the fastlane channel.

We open the Fastfile in the fastlane folder. We see custom_lane lane created by default. Let’s edit the lane.

The name of the lane is test. It runs on the FastlaneExampleiOSTestsscheme. It sends the results to the fastlane channel via webhook URL. Don’t forget to change the slack_url with your webhook URL.

Creating Test Scheme

Tests should run over a test scheme which is called FastlaneExampleiOSTests. Open the iOS project and create a new scheme which is called FastlaneExampleiOSTests.

Xcode Scheme

Also, enable Run as I mentioned it.


We are ready to run the lane. Open the terminal and go to the project path. Type fastlane test to the terminal. When tests are done, we see a message in the fastlane channel like that,


Full project → https://github.com/demirciy/FastlaneExampleiOS

Note: Please comment if any correction or better way exists then you can help everyone.

Leave a Reply:

Your email address will not be published.