如何进行测试分片或并行运行以实现颤振
Posted
技术标签:
【中文标题】如何进行测试分片或并行运行以实现颤振【英文标题】:How to do test sharding or run in parallel for flutter 【发布时间】:2021-02-26 23:53:54 【问题描述】:说明
我可以在测试包文档https://pub.dev/packages/test#sharding-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
当我尝试在我的项目中运行它时,我得到:
Could not find package "test". Did you forget to add a dependency?
pub finished with exit code 65
但是当我尝试从颤振运行测试命令时,我可以看到:
$ 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.
当我运行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/lcov.base.info".
Implies collecting coverage data. (Requires lcov)
--coverage-path Where to store coverage information (if coverage is enabled).
(defaults to "coverage/lcov.info")
--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.
我确实在测试文档https://pub.dev/packages/test#shuffling-tests 中看到了--test-randomize-ordering-seed
。
在我看来,flutter 本身缺少此功能,或者我没有寻找我应该寻找的地方。
环境
flutter: 1.22.3
dev_dependencies:
flutter_test:
sdk: flutter
问题
如何并行运行测试?
【问题讨论】:
【参考方案1】:目前不可能,但我做了这个 PR https://github.com/flutter/flutter/pull/76382,所以在部署之前它是可用的。
【讨论】:
以上是关于如何进行测试分片或并行运行以实现颤振的主要内容,如果未能解决你的问题,请参考以下文章