Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Add an option to print a code coverage summary to standard output

クローズ
#233 コメント 0 件 リアクション 2 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
52/100
issue の種類
機能追加
明瞭さ
おおむね明確
活発さ
静か
技術スタック
csharp
領域
cli, testing-qa

調査の方向性

Microsoft.Testing.Extensions.CodeCoverage のコマンドラインオプション処理と、示されている dotnet test の呼び出しで使用されるカバレッジ収集の完了パスから着手してください。要求された安定したサマリー動作を定義して実装し、その後、Cobertura アーティファクトが引き続き生成される一方で、標準出力にカバレッジの合計値が含まれることを確認してください。

索引モデルが issue の本文から書いたものです。

説明

Summary

Add an option to Microsoft.Testing.Extensions.CodeCoverage that prints a machine-readable code coverage summary to standard output after coverage collection completes.

The output should include at least the total line coverage percentage and ideally branch and method coverage as well.

This would allow CI systems such as GitLab to extract the coverage percentage directly from the test job output without requiring an additional script that reads and parses the generated Cobertura XML file.

Background and Motivation

I am using Microsoft Testing Platform together with the Microsoft.Testing.Extensions.CodeCoverage package in GitLab CI.

A typical test invocation looks similar to this:

dotnet test \
  --no-build \
  -- \
  --coverage \
  --coverage-output-format cobertura \
  --coverage-output coverage.cobertura.xml

The extension generates the requested coverage report, but it does not print a summary of the resulting coverage percentages to standard output.

GitLab uses the coverage keyword to extract a coverage percentage from the job log with a regular expression:

test:
  script:
    - dotnet test -- --coverage --coverage-output-format cobertura
  coverage: '/Line coverage:\s*(\d+(?:\.\d+)?)%/'

Because Microsoft.Testing.Extensions.CodeCoverage does not print the resulting percentage, there is no line for GitLab to match.

The current workaround is to add a separate script that:

  1. Locates the generated Cobertura XML report.
  2. Reads the root line-rate attribute.
  3. Converts the fractional value to a percentage.
  4. Prints a custom line to standard output.

For example:

COVERAGE_FILE=$(find tests-result/coverage -name 'Assembly*.xml' -print -quit)
LINE_RATE=$(awk -F'"' '/^<coverage / { print $2 }' "$COVERAGE_FILE")
awk -v rate="$LINE_RATE" 'BEGIN { printf "Assembly coverage: %.2f%%\n", rate*100 }'

This introduces platform-specific scripting and duplicates parsing logic that is already available inside the coverage extension when it produces the report.

It also makes the integration less convenient than other code coverage tools.

For example, Coverlet prints a coverage summary after collection, including line, branch, and method coverage. Coverlet also supports the teamcity output format, which emits service messages containing values such as:

CodeCoverageL
CodeCoverageB
CodeCoverageM
CodeCoverageAbsLTotal
CodeCoverageAbsLCovered

ReportGenerator provides text-based summary output through report types such as:

-reporttypes:TextSummary

It can read Cobertura and other coverage formats and generate a concise summary containing the total coverage values.

For C and C++ coverage, gcovr supports:

--print-summary

which prints a coverage summary while still allowing an XML report to be generated.

A similar capability directly in Microsoft.Testing.Extensions.CodeCoverage would simplify CI integration and eliminate the need for custom XML parsing.

Proposed Feature

Add a command-line option that prints a coverage summary after the report has been generated.

For example:

--coverage-print-summary

A test command could then look like this:

dotnet test \
  -- \
  --coverage \
  --coverage-output-format cobertura \
  --coverage-output coverage.cobertura.xml \
  --coverage-print-summary

The standard output could contain a stable summary such as:

Code coverage summary:
  Line coverage:   82.46% (1247/1512)
  Branch coverage: 71.18% (284/399)
  Method coverage: 79.03% (506/640)

GitLab could then extract the total line coverage with:

coverage: '/Line coverage:\s*(\d+(?:\.\d+)?)%/'

It would be useful to define the output as a stable, documented contract so that CI integrations can safely parse it.

An optional format argument could also be provided:

--coverage-summary-format <text|json|teamcity>

Possible formats could include:

text

Human-readable output suitable for terminal logs and regular-expression parsing:

Line coverage: 82.46%
Branch coverage: 71.18%
Method coverage: 79.03%
json

A single machine-readable line:

{"line":{"covered":1247,"total":1512,"percentage":82.46},"branch":{"covered":284,"total":399,"percentage":71.18},"method":{"covered":506,"total":640,"percentage":79.03}}

The minimum requested functionality is a stable text line containing total line coverage, for example:

Line coverage: 82.46%

The summary should be written to standard output by default when the option is enabled and should not replace the generated coverage artifact.

The feature should be included in Microsoft.Testing.Extensions.CodeCoverage, so users of Microsoft Testing Platform do not need to install another global tool or maintain an XML parsing script.

Alternative Designs

Always print a short summary

Instead of introducing a new option, the extension could always print a short coverage summary whenever collection succeeds:

Code coverage results: coverage.cobertura.xml
Line coverage: 82.46%

This would provide a useful default experience, but it would change the current console output. An explicit option would preserve backward compatibility.

Add a text output format

A new value could be added to --coverage-output-format:

--coverage-output-format text

However, this would make users choose between a coverage artifact and console output unless multiple output formats were also supported.

A separate summary option would allow users to generate Cobertura or XML while also printing the result to standard output.

Use ReportGenerator

ReportGenerator can read the generated report and produce a text summary:

reportgenerator \
  -reports:coverage.cobertura.xml \
  -targetdir:coverage-summary \
  -reporttypes:TextSummary

This works, but it requires an additional tool installation, another command, and another generated file.

The coverage extension already has access to the calculated totals, so printing them directly would be simpler and more efficient.

Use a custom XML parsing script

The pipeline can parse the Cobertura line-rate attribute with PowerShell, Python, xmllint, or another utility.

This is the current workaround, but it adds operating-system-specific code and must be duplicated across repositories.

Use Coverlet

Coverlet prints line, branch, and method totals after collection and also supports CI-oriented formats such as teamcity.

However, users who have selected Microsoft Testing Platform and Microsoft.Testing.Extensions.CodeCoverage should not need to switch coverage engines or add another collector only to obtain a console summary.

主要言語
C#
スター
125
フォーク
17
平均マージ
1時間 15分
マージ済み PR(30日)
2

環境構築

このプロジェクトの環境構築ファイルはまだ確認していません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

microsoft/codecoverage のほかの issue

microsoft/codecoverage の issue をすべて見る

似ている issue

C# の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。