Android 和 iOS 上的集成测试默认 golden-file 比较器已更改。
概述
#除非用户在测试中手动设置,或者通过 flutter_test_config.dart
文件设置了用户自定义的 goldenFileComparator
,否则 Android 和 iOS 设备及模拟器/仿真器将有一个新的默认设置,该设置代理到本地主机文件系统,修复了一个长期存在的 bug(#143299)。
背景
#integration_test
包及其与 flutter_test
的集成,过去存在一个 bug,在使用 matchesGoldenFile
或类似 API 时会抛出 FileSystemException
。
一些用户可能通过编写和使用自定义的 goldenFileComparator
来规避此问题。
dart
import 'package:integration_test/integration_test.dart';
import 'package:my_integration_test/custom_golden_file_comparator.dart';
void main() {
goldenFileComparator = CustomGoldenFileComparatorThatWorks();
// ...
}
此类变通方法不再需要,并且如果进行类型检查,默认设置将不再像以前那样工作。
dart
if (goldenFileComparator is ...) {
// The new default is a new (hidden) type that has not existed before.
}
迁移指南
#在大多数情况下,我们预计用户无需进行任何操作——这在某种意义上是“新”功能,取代了之前无法工作并导致测试失败的未处理异常的功能。
在用户编写了自定义测试基础设施和比较器的场景下,请考虑移除 goldenFileComparator
的覆盖,转而依赖(新的)默认设置,后者应该能按预期工作。
import 'package:integration_test/integration_test.dart';
-import 'package:my_integration_test/custom_golden_file_comparator.dart';
void main() {
- goldenFileComparator = CustomGoldenFileComparatorThatWorks();
// ...
}
有趣的事实:用于 web 平台的现有代码已被 复用。
时间线
#已合并版本:3.29.0-0.0.pre
稳定版发布:3.32
参考资料
#相关 API
flutter_test
,介绍了flutter_test_config.dart
及其功能。goldenFileComparator
,实现了比较功能,并且用户可配置。
相关问题
- Issue 143299,用户关于此长期存在 bug 的报告之一。
- Issue 160043,详细解释了
matchesGoldenFile
失败的原因。
相关 PR