Skip to content
This repository has been archived by the owner on May 18, 2023. It is now read-only.

Running and writing tests

nguyen_marc edited this page Aug 28, 2019 · 3 revisions

For the Toolbox

Dart tests are written using the flutter_test package's API, named with the suffix _test.dart, and placed inside the test/ subdirectory of the package under test.

We support several kinds of tests:

Running unit tests

Flutter tests use the flutter_test package (source, API documentation), which provides flutter-specific extensions on top of the Dart test package.

To automatically find all files named *_test.dart inside a package's test/ subdirectory, and run them inside the headless flutter shell as a test, use the flutter test command.

Individual tests can also be run directly, e.g.: flutter test my_app_test.dart

Unit tests run with flutter test run inside a headless flutter shell on your workstation, you won't see any UI. You can use print to generate console output or you can interact with the Dart VM via the Dart Observatory at http://localhost:8181/.

To debug tests in Observatory, use the --start-paused option to start the test in a paused state and wait for connection from a debugger. This option lets you set breakpoints before the test runs.

Instrumented tests run with flutter drive --target=test_driver/app.dart --driver=test_driver/*_test.dart run on an emulator or your own device. You can run all the tests by using test_integration.sh.

To learn how to see how well tested the codebase is, see Test coverage.