我正在尝试在 Flutter 项目上创建 CI 工作流程。
在这些工作流程中,我必须使用 flutter test
运行测试。
由于某些技术原因,我希望能够在某些工作流程中使用黄金图像运行测试,而其他一些工作流程则在忽略所有黄金图像检查的情况下运行测试。
有办法吗?
最佳答案
您可以使用强烈推荐的金色 toolkit .
如 this answer 中所述,您只需在 test/flutter_test_config.dart 中创建一个包含以下内容的文件:
import 'dart:async';
import 'dart:io';
import 'package:golden_toolkit/golden_toolkit.dart';
Future<void> testExecutable(FutureOr<void> Function() testMain) async {
return GoldenToolkit.runWithConfiguration(
() async {
await loadAppFonts();
await testMain();
},
config: GoldenToolkitConfiguration(
// Currently, goldens are not generated/validated in CI for this repo. We have settled on the goldens for this package
// being captured/validated by developers running on MacOSX. We may revisit this in the future if there is a reason to invest
// in more sophistication
skipGoldenAssertion: () => !Platform.isMacOS,
),
);
}
关于flutter - 如何在 flutter 测试中禁用对黄金图像的检查,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67404751/