Automate Flutter Testing With Github Actions

Flutter and Github Actions Logo

Overview

Prerequisites

Steps

Create a Flutter App in the root directory of the Github repository

flutter create --project-name myapp .
analyzer:
exclude:
- flutter/**

Create the Github Action

Parts:

Name

name: TEST FLUTTER APP

On

on:
push:
pull_request:
branches:
- main

Env

env:
FLUTTER_VERSION: "1.22.1"

Jobs

jobs:
tests:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v2
- name: Install Flutter
run: git clone https://github.com/flutter/flutter.git --depth 1 -b $FLUTTER_VERSION flutter
- name: Add Flutter to Path
run: echo "$GITHUB_WORKSPACE/flutter/bin" >> $GITHUB_PATH
- name: Install Dependencies
run: flutter pub get
- name: Flutter Analyze
run: flutter analyze --no-pub
- name: Check Flutter Formatting
run: flutter format lib/** --set-exit-if-changed
- name: Run Flutter Tests
run: flutter test --no-pub

All Together

name: TEST FLUTTER APPon:
push:
pull_request:
branches:
- main
env:
FLUTTER_VERSION: "1.22.1"
jobs:
tests:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v2
- name: Install Flutter
run: git clone https://github.com/flutter/flutter.git --depth 1 -b $FLUTTER_VERSION _flutter
- name: Add Flutter to Path
run: echo "$GITHUB_WORKSPACE/_flutter/bin" >> $GITHUB_PATH
- name: Install Flutter Dependencies
run: flutter pub get
- name: Flutter Analyze
run: flutter analyze --no-pub
- name: Check Flutter Formatting
run: flutter format lib/** --set-exit-if-changed
- name: Run Flutter Tests
run: flutter test --no-pub

Automated Testing In Action

Poorly written code fails the tests
Well written code passes the tests

Closing

Aspiring Developer

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store