Android 和 iOS 上的集成测试默认黄金文件比较器已更改。
概述
#除非在测试中手动设置了用户定义的 goldenFileComparator
,或使用了 flutter_test_config.dart
文件,否则 Android 和 iOS 设备以及模拟器/模拟器现在有了一个新的默认设置,该设置代理到本地主机文件系统,从而修复了一个长期存在的错误(#143299)。
背景
#软件包 integration_test
及其与 flutter_test
的集成历来存在一个错误,即在使用 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
,实现比较功能,且可由用户配置。
相关问题
- 问题 143299,众多关于该长期存在错误的的用户报告之一。
- 问题 160043,详细解释了
matchesGoldenFile
失败的技术原因。
相关 PR