Skip to content

Instantly share code, notes, and snippets.

@psygo
Last active October 8, 2020 00:00
Show Gist options
  • Save psygo/7801c4928cf27f89330d138f907ff77b to your computer and use it in GitHub Desktop.
Save psygo/7801c4928cf27f89330d138f907ff77b to your computer and use it in GitHub Desktop.
Code Coverage with Pure Dart

Gathering Code Coverage

  1. Install the coverage package:
    pub global activate coverage
  2. Create a test file for running all of the tests.
  3. Run — in this case, the file with all of the tests is called .test_coverage.dart —:
    dart --pause-isolates-on-exit --disable-service-auth-codes --enable-vm-service=NNNN test/.test_coverage.dart
  4. Use the observatory's address to collect coverage:
    pub global run coverage:collect_coverage --uri=http://127.0.0.1:63243/ -o coverage.json
  5. Format the coverage to the LCOV format:
    pub global run coverage:format_coverage --lcov -i coverage.json -o lcov.info

GM Passos' Suggestion

The source is here.

echo ""
echo "[RUNNING TEST + COVERAGE]"
pub run test_coverage --no-badge  --print-test-output  --min-coverage 40

rm coverage_badge.svg

echo ""
echo "[GENERATING COVERAGE REPORT AT ./coverage]"
genhtml ./coverage/lcov.info -o coverage

echo ""
echo "[OPENING ./coverage/index.html]"
open ./coverage/index.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment