搜索插件、代码仓与 APP 分类

插件详情v0.5.0

test_coverage

命令行实用程序,用于在 Dart VM 中运行测试并收集覆盖率数据。

近 30 天下载
1570
喜欢数
44
Pub 分数
30

安装插件

flutter pub add test_coverage

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

一个命令行实用程序,用于在 VM 上运行 Dart 测试并收集覆盖率数据。它帮助开发人员衡量其代码有多少部分被测试覆盖,从而提高测试质量并识别未测试的代码路径。该工具可无缝集成到 CI/CD 流水线中,并支持单元测试和集成测试。覆盖率报告可以生成多种格式,便于分析和报告。设计简洁高效,特别适合希望保持高测试覆盖率标准的团队。

适合场景

  • 在CI/CD工作流中测量测试覆盖率
  • 识别未测试的代码区域
  • 为团队评审生成覆盖率报告
  • 与自动化测试流水线集成
  • 发布前验证测试的完整性
  • 随时间监测覆盖率趋势

主要特点

  • 在 Dart VM 上运行测试
  • 收集详细的代码覆盖率数据
  • 支持单元测试和集成测试
  • 生成覆盖率报告
  • 轻松的 CLI 集成
  • 与 Flutter 和 Dart 项目兼容

适合对象

  • Dart 和 Flutter 开发人员
  • 专注于测试质量的团队
  • CI/CD 自动化工程师
  • 需要覆盖率合规的项目
  • 开发者提升测试覆盖率
  • 质量保证团队

使用建议

  • 需要设置 Dart SDK
  • 无内置可视化(需要外部工具)
  • 仅限基于虚拟机的测试
  • Web 或移动平台的覆盖率数据不可用
  • 可能需要为复杂项目进行额外配置
  • 在测试期间不支持热重载

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

test_coverage Build Status Pub Coverage

A simple command-line tool to collect test coverage information from Dart VM tests. It is useful if you need to generate coverage reports locally during development.

Usage

Add dev dependency to your pubspec.yaml:

dev_dependencies:
  test_coverage: ^0.4.2

Run pub get to install. Then, in the root of your project run:

pub run test_coverage

Result is saved in coverage/lcov.info. If you have lcov tool installed on your system (for Mac it's brew install lcov) you can generate coverage reports using genhtml command:

genhtml -o coverage coverage/lcov.info
# Open in the default browser (mac):
open coverage/index.html

Integrations

Resulting coverage/lcov.info file is ready to be consumed by Codecov command-line tool, so no extra step is needed.

This library was not tested with coveralls yet.

Generating badge image

Coverage

Coverage badge SVG image is automatically generated and saved to coverage_badge.svg in your project root directory. You can add it to Git and use in README.md on Github as follows:

![Coverage](https://raw.githubusercontent.com/{you}/{repo}/master/coverage_badge.svg?sanitize=true)

If you don't need it you can pass --no-badge flag when running test coverage.

Known limitations

  • This library was created to run Dart VM tests. It has not been tested and likely won't work for Dart code targeting web platform (compiled to JavaScript). There is no need to use this tool for Flutter as it allows collecting coverage information with flutter test --coverage.

How it works

The tool performs following steps:

1. Generates test/.test_coverage.dart file (a "test all" script).

Scans your test/ directory to find all *_test.dart files and creates test/.test_coverage.dart which imports all found test files and runs corresponding main() of all tests functions within the same file (and process), which simplifies collection of coverage information.

It is recommended to add this file to your .gitignore.

Below is an example of test/.test_coverage.dart:

// Auto-generated by test_coverage. Do not edit by hand.
// Consider adding this file to your .gitignore.

import 'some_test.dart' as some_test;
import 'nested/other_test.dart' as other_test;
import 'some_other_test.dart' as some_other_test;

void main() {
  some_test.main();
  other_test.main();
  some_other_test.main();
}
2. Runs the tests

Following command is used to run the tests:

dart --pause-isolates-on-exit --enable_asserts --enable-vm-service \
  test/.test_coverage.dart
3. Collects and formats coverage information

When test execution is completed the tool uses functionality of the coverage package to collect and format coverage report.

Feel free to file feature requests and bug reports at the issue tracker.

4. Minimal coverage percentage

Set minimal coverage percentage to pass min-coverage percentage value of coverage.

5. See test output

print-test-output to show test output.

Show output of tests

Feel free to file feature requests and bug reports at the issue tracker.

所属分类

依赖

依赖清单 5 项

源码仓库

使用此插件的项目