VM에서 Dart 테스트를 실행하고 커버리지 데이터를 수집하기 위한 명령줄 유틸리티입니다. 개발자가 테스트가 코드의 어느 정도를 커버하고 있는지 측정할 수 있도록 도와주며, 더 나은 테스트 품질과 미테스트된 코드 경로를 식별하는 데 도움을 줍니다. 이 도구는 CI/CD 파이프라인에 원활하게 통합되며, 단위 테스트와 통합 테스트 모두를 지원합니다. 다양한 형식으로 커버리지 보고서를 생성하여 분석 및 보고에 활용할 수 있습니다. 간단함과 효율성을 고려해 설계되어, 높은 테스트 커버리지 기준을 유지하려는 팀에게 특히 유용합니다.
사용 사례
CI/CD 워크플로에서 테스트 커버리지 측정
테스트되지 않은 코드 영역 식별
팀 리뷰를 위한 커버리지 보고서 생성
자동화된 테스트 파이프라인과의 통합
릴리스 전 테스트 완전성 검증
시간에 따른 모니터링 커버리지 추세
주요 기능
Dart VM에서 테스트를 실행합니다
세부적인 코드 커버리지 데이터를 수집합니다
단위 및 통합 테스트를 지원합니다
커버리지 보고서 생성
간편한 CLI 통합
Flutter 및 Dart 프로젝트와 호환됩니다
적합한 대상
Dart 및 Flutter 개발자
테스트 품질에 집중하는 팀
CI/CD 자동화 엔지니어
카バレ지 준수를 요구하는 프로젝트
개발자가 테스트 커버리지 향상 중
품질 보증 팀
고려 사항
Dart SDK 설정이 필요합니다
내장된 시각화 없음(외부 도구 필요)
가상 머신 기반 테스트에 제한됨
웹 또는 모바일 플랫폼에 대한 커버리지 데이터를 사용할 수 없습니다
복잡한 프로젝트의 경우 추가 구성이 필요할 수 있습니다
테스트 중에 핫 리로드를 지원하지 않습니다
원본 README
연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.
test_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 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:
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;
voidmain() {
some_test.main();
other_test.main();
some_other_test.main();
}