flutter-test-discovery
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseFlutter test discovery
Flutter测试文件识别
Ensure every intended test file actually runs. The runner is a names filter: only files matching are discovered by with no arguments.
*_test.dartflutter test确保每个目标测试文件都能实际运行。测试运行器是一个名称过滤器:不带参数的只会识别匹配的文件。
flutter test*_test.dartSteps
步骤
- When the test counter looks low, list the test directory and check names:
— any file ending in
ls test/(plural) will be silently skipped. Completion: you can name every file and whether it ends in_tests.dart._test.dart - Rename non-conforming files so the suite is discovered: .
mv test/acceptance_tests.dart test/acceptance_test.dart - Re-run the full suite and compare the counter to the expected total. Completion: counter matches; the acceptance file's tests appear in the summary.
- Run a single case while debugging with .
flutter test test/<file>_test.dart --plain-name 'TEST-003'
- 当测试计数看起来偏低时,列出测试目录并检查文件名:
— 任何以
ls test/(复数形式)结尾的文件都会被静默跳过。 完成标志:你可以列出所有文件及其是否以_tests.dart结尾。_test.dart - 重命名不符合规则的文件,使其能被测试套件识别:。
mv test/acceptance_tests.dart test/acceptance_test.dart - 重新运行完整测试套件,并将计数与预期总数对比。完成标志:计数匹配;验收测试文件中的测试会出现在汇总结果中。
- 调试时运行单个测试用例,使用命令。
flutter test test/<file>_test.dart --plain-name 'TEST-003'
Reference
参考信息
- Evidence from this project: reported
flutter testwhile 28 tests existed; the 14 acceptance tests in+14were silently excluded until renamed toacceptance_tests.dart.acceptance_test.dart - Per-file runs () work with any name — the discovery gap only bites the full-suite run.
flutter test test/x.dart - If a full-suite run seems too fast, suspect a name, not the tests.
- 项目实例:报告执行了
flutter test个测试,但实际存在28个测试;+14中的14个验收测试在重命名为acceptance_tests.dart之前一直被静默排除。acceptance_test.dart - 单个文件运行()支持任意文件名——只有在运行完整测试套件时才会出现文件识别遗漏的问题。
flutter test test/x.dart - 如果完整测试套件运行速度异常快,应怀疑是文件名问题,而非测试本身的问题。