DevTools is test covered by multiple types of tests, all of which are run on the CI for each DevTools PR / commit:
The following instructions are for unit tests, widget tests, and partial integration tests.
- For instructions on running and writing full integration tests, please see integration_test/README.md. In general, we should first try to test cover new features and bug fixes with unit tests or widget tests before writing new integration tests, which are slower to run and are not as easy to debug or iterate upon.
- For instructions on running and writing benchmark tests, please see benchmark/README.md.
Before running tests, make sure your Flutter SDK matches the version that will be used on the CI.
Note: this step requires that you have followed the set up instructions in the DevTools contributing guide regarding cloning the Flutter SDK from GitHub, adding the
dt
executable to your PATH, and runningflutter pub get
in thetool
directory.
To update your local flutter version, run:
dt update-flutter-sdk --update-on-path
Warning: this will delete any local changes in your Flutter SDK you checked out from git.
You may need to re-generate the testing mocks before running the tests:
dt generate-code --upgrade
cd packages/devtools_app flutter test test/
Note: golden images should only be generated on MacOS.
Golden image tests will fail for one of three reasons:
For valid golden image updates (1 and 2 above), the failing golden images will need to be updated. This can be done in one of two ways:
(Recommended) If the tests failed on the CI for a PR, we can download the generated golden images directly from GitHub.
If you are developing on a non-MacOS machine, this is the only way you'll be able to update the golden images.
Navigate to the failed Actions run for your PR on GitHub. Example:
Scroll to the bottom of the Summary view to see the errors from the macos goldens
job, and the notice containing the golden update command:
Copy this command and run it locally to apply the golden updates. Please review these updates and ensure they are acceptable golden changes. Important: this command will only succeed after the golden artifacts have been uploaded to Github, which happens once all of the jobs have finished.
Update the goldens locally by running the failing test(s) with the --update-goldens
flag.
Due to slight differences in the MacOS environment used by Github actions and your local machine, the locally generated goldens may still cause failures on the CI. This is why option #1 above is the recommended method for updating goldens images.
Before updating the goldens, ensure your version of Flutter matches the version of Flutter that is used on the CI (see prerequsites above).
Then proceed with updating the goldens:
flutter test <path/to/my/test> --update-goldens
or to update goldens for all tests:
flutter test test/ --update-goldens
When you add a new feature or fix a bug, please add a corresponding test for your change.
_test.dart
suffix, and place it in an appropriate location under the test/
directory for the DevTools package you are working on.