Giter Club home page Giter Club logo

full_testing_flutter's Introduction

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

full_testing_flutter's People

Contributors

chinnonsantos avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.