You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何修改Flutter test文件搜索模式,去除_test后缀?

让flutter_test识别非_test后缀的测试文件的配置方法

在Dart/Flutter生态中,有两种方式可以配置flutter_test的测试文件匹配规则,替代默认的*_test.dart模式:

1. 命令行临时指定

运行测试时,通过--pattern参数自定义文件名匹配正则:

# 匹配所有.dart文件作为测试文件
flutter test --pattern ".*\.dart"

# 仅匹配tests目录下的所有.dart文件
flutter test tests/ --pattern ".*\.dart"

2. 持久化配置(推荐)

在项目根目录创建dart_test.yaml文件,配置全局的文件匹配规则:

# 匹配所有.dart文件
file_pattern: ".*\\.dart"

之后直接运行flutter test,就会自动应用这个规则,无需每次输入参数。

3. 配置快捷脚本(可选)

如果觉得每次敲命令麻烦,可以在pubspec.yaml中添加自定义测试脚本:

scripts:
  test-all: flutter test --pattern ".*\.dart"

运行时只需执行:

flutter pub run test-all

内容的提问来源于stack exchange,提问作者Jasper van den Bosch

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.06 04:20:32