【问题标题】:How to exclude file in flutter test coverage?如何在颤振测试覆盖率中排除文件?
【发布时间】:2019-05-08 00:19:22
【问题描述】:

我正在尝试从flutter 测试结果的测试覆盖结果中排除几个config 文件。当我运行flutter test --coverage 时,输出文件icov.info 也包含有关config 文件的信息,这会影响整体覆盖率。

【问题讨论】:

  • 你使用的是什么类型的配置文件?
  • @Muldec,一个保存所有常量/密码/等的 Dart 文件,也用于翻译文件,不需要测试覆盖率。基本上,问题是如何从测试覆盖中跳过几个文件。
  • 今天不可能。对不起。
  • 你能做到吗?

标签: dart flutter code-coverage flutter-test


【解决方案1】:

有一个方便的包可以做到这一点remove_from_coverage

https://pub.dev/packages/remove_from_coverage

这是使用帮助:

Remove files with paths matching given PATTERNs from the lcov.info FILE
-f, --file=<FILE>         the target lcov.info file to manipulate
-r, --remove=<PATTERN>    a pattern of paths to exclude from coverage
-h, --help                show this help

如果你想在你的管道中运行它或全局安装它,基本上将它添加到你的dev_dependencies

【讨论】:

    【解决方案2】:

    如果你使用的是 lcov,你可以这样做:

    - flutter test --coverage
    - lcov --remove coverage/lcov.info 'lib/mock/*' 'lib/utils/l10n/*' 'lib/utils/colors.dart' -o coverage/new_lcov.info
    - genhtml coverage/new_lcov.info --output=coverage
    

    【讨论】:

    • 伟大而简单的选择!
    猜你喜欢
    • 1970-01-01
    • 2019-07-03
    • 2019-09-25
    • 2017-07-23
    • 2020-06-01
    • 2015-11-15
    • 2014-12-15
    • 2019-04-10
    • 1970-01-01
    相关资源
    最近更新 更多