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