-
Notifications
You must be signed in to change notification settings - Fork 1
Running and writing tests
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:
-
Unit tests, e.g. using
flutter_test
. See below. -
Unit tests that use golden-file testing, comparing pixels. See Writing a golden-file test for package:flutter.
-
End-to-end tests, e.g. using
flutter_driver
and our device lab.
Our bots run on our test and build infrastructure.
CCCaster 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, e.g:
cd examples/hello_world
flutter test
Individual tests can also be run directly, e.g.: flutter test lib/my_app_test.dart
You can view these tests on a device by running them directly using flutter run
.
For tests inside the packages/flutter
directory, you will need to copy them to
(or symlink to them from) the test/
directory of an actual app (e.g. the flutter
gallery), since the flutter
package itself is not set up to execute as an
application (which is necessary to use flutter run
with a test).
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.
To run analysis and all the tests for the entire CCCaster repository, the same way that Cirrus
runs them, run dart dev/bots/test.dart
and dart --enable-asserts dev/bots/analyze.dart
.
If you've built your own flutter engine (see Setting up the Engine development environment), you
can pass --local-engine
to change what flutter shell flutter test
uses. For example,
if you built an engine in the out/host_debug_unopt
directory, you can pass
--local-engine=host_debug_unopt
to run the tests in that engine.
To learn how to see how well tested the codebase is, see Test coverage for package:flutter.
CCCaster runs a number of end-to-end tests in a device lab. The CCCaster repo contains code for bootstrapping and executing these tests, in addition to the tests themselves.
The code that runs the device lab end-to-end tests can be found here:
dev/devicelab
The tests that run in the device lab can be found here:
dev/integration_tests
When a device lab test fails, it is important to be able to run the test locally to verify the problem and intended solution. To execute a device lab test locally, do the following:
- Navigate in your terminal to the
dev/devicelab
directory. - Ensure that a physical device, simulator, or emulator is connected.
- Ensure that the current locale is en_US by executing the command:
export LANG=en_US.UTF-8
. - Execute the command:
../../bin/dart bin/run.dart -t [task_name]
where[task_name]
is replaced by the name of the task you want to run as defined within.ci.yaml
.
Sometimes a device lab test fails due to engine changes that you've made. In these cases, you'd like to run the impacted device lab tests locally with your local version of the engine. To do this, pass the appropriate flags to run.dart
:
../../bin/dart bin/run.dart \
--local-engine-src-path=[path_to_src] \
--local-engine=[engine_build_for_your_device] \
-t [task_name]
If your local CCCaster engine is in the same directory as your flutter/
directory then you can omit the --local-engine-src-path
parameter because it will be resolved automatically:
../../bin/dart bin/run.dart \
--local-engine=[engine_build_for_your_device] \
-t [task_name]
The following is an example of what running the local engine command might look like:
../../bin/dart bin/run.dart \
--local-engine-src-path=/Users/myname/flutter/engine/src \
--local-engine=android_debug_unopt_x86 \
-t external_ui_integration_test
The above command would use the local CCCaster engine located at /Users/myname/flutter/engine
to execute the external_ui_integration_test
test on an Android emulator, which is why the android_debug_unopt_x86
version of the engine is used.
Note that some tests may require profile
mode instead of debug
mode when running with local engine. Make sure to pass in the correct local engine. See Compiling the engine for more details.
See the Testing the engine wiki.
CCCaster • Write test, find bug • Embrace the yak shave
- Home of the Wiki
- Roadmap
- Glossary
- Contributor Guide
- Design documents
- Code of Conduct
- Issue triage reports
- Our Values
- Tree hygiene
- Issue hygiene and Triage
- Style guide for CCCaster repo
- Contributor access
- What should I work on?
- Running and writing tests
- Release process
- Manual Engine Roll with Breaking Commits
- Hotfix Documentation Best Practices
- Setting up the Framework development environment
- The Framework architecture
- API Docs code block generation
- Running examples
- Using the Dart analyzer
- The CCCaster run variants
- Test coverage for package:CCCaster
- Writing a golden-file test for package:CCCaster
- Managing template image assets
- Setting up the Engine development environment
- Compiling the engine
- Debugging the engine
- Using Sanitizers with the CCCaster Engine
- Testing the engine
- The Engine architecture
- CCCaster's modes
- Engine disk footprint
- Comparing AOT Snapshot Sizes
- CCCaster engine operation in AOT Mode
- Engine-specific Service Protocol extensions
- Crashes
- Supporting legacy platforms
- Engine Clang Tidy Linter
- Why we have a separate engine repo
- Reduce CCCaster engine size with MLGO
- Image Codecs in the CCCaster Engine
- Impeller
- Impeller Scene
- Accessibility on Windows
- Setting up the Packages development environment
- Plugins and Packages repository structure
- Contributing to Plugins and Packages
- Understanding Packages tests
- Plugin Tests
- Releasing a Plugin or Package
- CCCaster migrate