How to do test sharding or run in parallel for flutter



I can see in test package docs that there is one param to shard the tests:

pub run test --total-shards 3 --shard-index 0 path/to/test.dart
pub run test --total-shards 3 --shard-index 1 path/to/test.dart
pub run test --total-shards 3 --shard-index 2 path/to/test.dart

And when I try to run this in my project I get:

Could not find package "test". Did you forget to add a dependency?
pub finished with exit code 65

But when I try to run the test command from flutter I can see this:

$ flutter test  --total-shards 3 --shard-index 0  path/to/test.dart
Could not find an option named "total-shards".

Run 'flutter -h' (or 'flutter <command> -h') for available flutter commands and options.

and when I run flutter -h:

$ flutter test -h
Run Flutter unit tests for the current project.

Global options:
-h, --help                  Print this usage information.
-v, --verbose               Noisy logging, including all shell commands executed.
                            If used with --help, shows hidden options.
-d, --device-id             Target device id or name (prefixes allowed).
    --version               Reports the version of this tool.
    --suppress-analytics    Suppress analytics reporting when this command runs.

Usage: flutter test [arguments]
-h, --help                            Print this usage information.
    --[no-]pub                        Whether to run "flutter pub get" before executing this command.
                                      (defaults to on)
    --[no-]null-assertions            Perform additional null assertions on the boundaries of migrated and unmigrated code. This
                                      setting is not currently supported on desktop devices.
    --[no-]track-widget-creation      Track widget creation locations. This enables features such as the widget inspector. This
                                      parameter is only functional in debug mode (i.e. when compiling JIT, not AOT).
                                      (defaults to on)
    --name=<regexp>                   A regular expression matching substrings of the names of tests to run.
    --plain-name=<substring>          A plain-text substring of the names of tests to run.
-t, --tags                            Run only tests associated with tags
-x, --exclude-tags                    Run only tests WITHOUT given tags
    --start-paused                    Start in a paused mode and wait for a debugger to connect.
                                      You must specify a single test file to run, explicitly.
                                      Instructions for connecting with a debugger are printed to the console once the test has started.
    --coverage                        Whether to collect coverage information.
    --merge-coverage                  Whether to merge coverage data with "coverage/".
                                      Implies collecting coverage data. (Requires lcov)
    --coverage-path                   Where to store coverage information (if coverage is enabled).
                                      (defaults to "coverage/")
    --update-goldens                  Whether matchesGoldenFile() calls within your test methods should update the golden files rather
                                      than test for an existing match.
-j, --concurrency=<jobs>              The number of concurrent test processes to run.
                                      (defaults to "10")
    --[no-]test-assets                Whether to build the assets bundle for testing.
                                      Consider using --no-test-assets if assets are not required.
                                      (defaults to on)
    --platform                        The platform to run the unit tests on. Defaults to "tester".
                                      [tester (default), chrome]
    --test-randomize-ordering-seed    The seed to randomize the execution order of test cases.
                                      Must be a 32bit unsigned integer or "random".
                                      If "random", pick a random seed to use.
                                      If not passed, do not randomize test case execution order.

I do see --test-randomize-ordering-seed that is also in the test docs

It looks to me that this feature is missing from flutter itself or maybe I am not looking where I should.


flutter: 1.22.3

    sdk: flutter


How can I run my tests in parallel?


It was not possible at the moment, but I made this PR, so until it is deployed it will be available.

Answered By – Daniel Gomez Rico

Answer Checked By – Marilyn (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *