如何使用在 Flutter 中呈现良好的字体进行黄金测试?
How to make golden tests with fonts well rendered in Flutter?
要在没有 Flutter 测试的默认方块字体“Ahem”的情况下呈现图像,需要采取哪些步骤?
这对我有用:
创建 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,
),
);
}
包含在pubspec.yaml
中:
dev_dependencies:
golden_toolkit: ^0.7.0
flutter:
uses-material-design: true
assets:
- assets/images/
fonts:
- family: Roboto
fonts:
- asset: assets/fonts/Roboto/Roboto-Regular.ttf
创建目录:mkdir assets/{images,fonts}
并下载 Roboto font 到字体目录
确保那个可能是空的images dir created
要在没有 Flutter 测试的默认方块字体“Ahem”的情况下呈现图像,需要采取哪些步骤?
这对我有用:
创建 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,
),
);
}
包含在pubspec.yaml
中:
dev_dependencies:
golden_toolkit: ^0.7.0
flutter:
uses-material-design: true
assets:
- assets/images/
fonts:
- family: Roboto
fonts:
- asset: assets/fonts/Roboto/Roboto-Regular.ttf
创建目录:mkdir assets/{images,fonts}
并下载 Roboto font 到字体目录
确保那个可能是空的images dir created