【问题标题】:How to make golden tests with fonts well rendered in Flutter?如何使用 Flutter 中良好渲染的字体进行黄金测试?
【发布时间】:2021-02-23 13:08:37
【问题描述】:

要在不使用 Flutter 测试的默认纯正方形字体“Ahem”的情况下渲染图像,需要采取哪些步骤?

【问题讨论】:

    标签: flutter flutter-test


    【解决方案1】:

    这对我有用:

    使用:创建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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-03-25
      • 1970-01-01
      • 1970-01-01
      • 2021-03-19
      • 2011-04-25
      • 1970-01-01
      • 2021-06-13
      相关资源
      最近更新 更多