【发布时间】:2021-07-27 23:30:38
【问题描述】:
我正在尝试在 Flutter 项目上创建 CI 工作流程。
在这些工作流程中,我必须使用 flutter test 运行测试。
由于某些技术原因,我希望能够在某些工作流程中使用黄金映像运行测试,而其他一些工作流程则在忽略所有黄金映像检查的情况下运行测试。
有办法吗?
【问题讨论】:
标签: flutter dart testing flutter-test
我正在尝试在 Flutter 项目上创建 CI 工作流程。
在这些工作流程中,我必须使用 flutter test 运行测试。
由于某些技术原因,我希望能够在某些工作流程中使用黄金映像运行测试,而其他一些工作流程则在忽略所有黄金映像检查的情况下运行测试。
有办法吗?
【问题讨论】:
标签: flutter dart testing 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,
),
);
}
【讨论】: