搜尋套件、儲存庫與 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 項

原始碼儲存庫

使用此套件的專案