/full_testing_flutter

Flutter App's simplest automated full test

Primary LanguageDartMIT LicenseMIT

Flutter App's simplest automated full test

Codemagic build status Travis build status Codecov coverage Flutter version GitHub license Twitter follow Slack channel Open source Love

This project shows an example of the main forms of automated testing in Flutter mobile App, including integration into a CI/CD platform, as follows:

Using native libraries or recommended by official Flutter documentation (Google).

Note that everything here fits within the guidelines set out in Effective Dart.

Codemagic - CI for Flutter

At the Flutter Live 2018 conference in London, Nevercode launched their dedicated CI/CD solution for Flutter apps which is known as Codemagic.

This project uses Codemagic for CI/CD, selected after various analysis and testing with other CI platforms (Travis CI, Codecov, Coveralls...), which support the Dart language (in some cases only Dart < 2.0), but do not have good support for the Flutter App.

"Codemagic is the official CI/CD solution dedicated just for Flutter apps." - Getting Started with Codemagic

See more details about Codemagic in 'Getting Started with Codemagic'.

Prerequisites

You will need Flutter framework v1.11.0 or above installed (Channel beta, on Linux, locale en_US.UTF-8).

The Dart SDK is not required because Flutter has Dart language support as an integrated tool in the framework.

Libraries:

Running tests

To automatically formatting code, run:

flutter format lib test test_driver

To analyzing the Dart language code, run:

flutter analyze

The Dart analyzer will check your code and look for possible errors.

To testing the project, run:

flutter test

To check test coverage, run:

  • Run test with --coverage flag:

    flutter test --coverage
    
  • Convert the LCOV report generated to a readable HTML file:

    genhtml coverage/lcov.info -o coverage/html
    

    The flutter test --coverage command will generate a lcov.info file, you will need to install the LCOV program to convert (genhtml ...) the report to an HTML file (human readable).

  • Open the HTML report (with a Web Browser)

    google-chrome coverage/html/index.html
    

To test only Unit tests of the project, run:

flutter test test/unit/

To test only Widget tests of the project, run:

flutter test test/widget/

To test only Integration (or assertion) of the project, run:

flutter drive --target=test_driver/app.dart

-->> First, be sure to launch an Android Emulator, iOS Simulator, or connect your computer to a real iOS / Android device. Integration testing needs to be executed on a real system (simulator or device)!

"Unlike unit and widget tests, integration test suites do not run in the same process as the app being tested. Therefore, create two files that reside in the same directory. By convention, the directory is named test_driver." - An introduction to integration testing

To run Formatting code ✔️; Analyzing code 🔍; Unit test code 🆗; Widget test 📲 and Test coverage ☔️. everything together ⏲️:

sh scripts/flutter_test.sh

Drive testing on AWS Device Farm with Sylph

To runs Flutter integration tests on real devices in cloud, use the Sylph.

  • Install Sylph:

    pub global activate sylph
    

    For more details see Sylph.

  • Configure the AWS CLI credentials:

    $ aws configure
    AWS Access Key ID [None]: YOUR_KEY_ID_HERE
    AWS Secret Access Key [None]: YOUR_SECRET_ACCESS_KEY_HERE
    Default region name [None]: us-west-2
    Default output format [None]: json
    

    The AWS Device Farm is only available in Oregon region (us-west-2)!

  • Run the Sylph:

    sylph
    

    Sylph uses the sylph.yaml file in this repository to configure and run device on AWS.

    By default, it has only two Android devices (Samsung Galaxy S9+ and Samsung Galaxy J7). Running iOS devices requires an Apple Developer Certificate (Team ID), We don't cover this steps!

    Screenshot from 2019-11-26 16-36-14

Drive testing on Codemagic CI/CD (using AWS Device Farm and Sylph)

Execute the same process when previous step "Drive testing on AWS Device Farm with Sylph".

When you can run local drive testing with Sylph on AWS Device Farm, see this article to learn how to configure Codemagic console to automate the process.

Screenshot from 2019-11-27 09-53-00

Running the APP

To start the mobile App example, run:

flutter run

License

Copyright © 2019 | Chinnon Santos | MIT