Code Monkey home page Code Monkey logo

flutter_test_app's Introduction

testing_app NANDA

A Sample app that shows different types of testing in Flutter.

This particular sample uses the Provider package but any other state management approach would do.

Goals for this sample

Show how to perform:

  • Widget Testing,
  • Integration Testing,
  • Performance Testing, and
  • State Management Testing using the Provider package.

How to run tests

  • Navigate to the project's root folder using command line and follow the instructions below.

To run tests using only the Flutter SDK:

The Flutter SDK can run unit tests and widget tests in a virtual machine, without the need of a physical device or emulator.

  • To run all the test files in the test/ directory in one go, run flutter test.
  • To run a particular test file, run flutter test test/<file_path>

To run tests on a physical device/emulator:

  • Widget Tests:
    • Run flutter run test/<file_path>
  • Integration Tests:
    • Run flutter test integration_test to run all the integration tests with a single command.
    • Alternatively, you can run flutter drive --driver=integration_test/driver.dart --target=integration_test/app_test.dart to run them separately. You can also provide custom driver files with this command.
  • Performance Tests:
    • Run flutter drive --driver=integration_test/perf_driver.dart --target=integration_test/perf_test.dart --profile --trace-startup
      • Using a physical device and running performance tests in profile mode is recommended.
      • The --trace-startup option is used to avoid flushing older timeline events when the timeline gets long.
  • State Management Tests:
    • For testing state using Flutter Integration Tests
      • Run flutter drive --driver=integration_test/driver.dart --target=integration_test/state_mgmt_test.dart

To generate test coverage report:

  • Install the lcov tool:
    • For MacOS, run brew install lcov
    • For Linux, run sudo apt install lcov
  • Run tests with coverage:
    • flutter test --coverage
  • Convert lcov.info into readable html:
    • Run genhtml coverage/lcov.info -o coverage/index
  • Open coverage/index/index.html in your preferred browser.

CI/CD

  • Refer .github and the tool directory to see how to test Flutter projects using GitHub Actions.

Note that tools like GitHub Actions can't run tests on a physical device, which is required to run integration tests. Instead, you can use Firebase Test Lab, Codemagic or any platform of your choice to do that.

Questions/issues

If you have a general question about testing in Flutter, the best places to go are:

If you run into an issue with the sample itself, please file an issue.

flutter_test_app's People

Contributors

nandak99 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.