如何获得Dart运行时的代码覆盖率?

时间:2019-11-18 12:52:15

标签: flutter dart runtime code-coverage

简而言之:谁能告诉我如何知道是否已调用飞镖代码或如何将其标记为命中和未命中。

我们可以通过'flutter test --coverage'获得测试覆盖率。但这依赖于test.dart文件,我的意思是我们必须为我们关心的文件和功能编写test.dart文件。如果我们可以在运行dart时收集覆盖率信息,那么我们将更容易知道已调用了哪些代码行。而且我认为这对开发人员将很友好。

我搜索了dart-lang / sdk,只知道'flutter test --coverage'是通过invokeRpcRaw('getSourceReport'...)获取报告的,但是我不知道如何获取dart运行时的报告。

如果运行时无法正常工作,我可以在编译时做些什么吗?

2 个答案:

答案 0 :(得分:0)

在Mac上

brew install lcov

或者为此使用ubuntu或Windows替代方案

然后

flutter test --coverage
genhtml coverage/icov.info -o coverage/html
open coverage/html

答案 1 :(得分:0)

https://github.com/dart-lang/coverage可能会帮助您

  1. flutter pub全球激活报道
  2. 颤动运行(可以使用-d选择设备)
  3. flutter pub全球运行覆盖率:collect_coverage --uri = http:// ... -o coverage.json --resume-isolates
  4. flutter pub全局运行覆盖率:format_coverage --packages =。/。packages --report-on lib --in coverage.json --out lcov.info --lcov

我已经尝试过了,最后在运行时获得了lcov.info,祝您好运

相关问题