Skip to content

Update dotnet-coverage docs. Adding uninstrument command #43961

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
153 changes: 128 additions & 25 deletions docs/core/additional-tools/dotnet-coverage.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ ms.topic: reference
## Synopsis

```console
dotnet-coverage [-h, --help] [--version] <command>
dotnet-coverage <command> [-h, --help] [--version]
```

## Description
Expand Down Expand Up @@ -49,6 +49,7 @@ dotnet tool install --global dotnet-coverage
| [dotnet-coverage snapshot](#dotnet-coverage-snapshot) |
| [dotnet-coverage shutdown](#dotnet-coverage-shutdown) |
| [dotnet-coverage instrument](#dotnet-coverage-instrument) |
| [dotnet-coverage uninstrument](#dotnet-coverage-uninstrument) |

## dotnet-coverage merge

Expand All @@ -62,10 +63,12 @@ The `merge` command is used to merge several code coverage reports into one. Thi

```console
dotnet-coverage merge
<files>...
[--remove-input-files]
[-o|--output <output>] [-f|--output-format <output-format>]
[-l|--log-file <log-file>] [-ll|--log-level <log-level>] [-?|-h|--help]
<files>
[-l|--log-file <log-file>] [-ll|--log-level <log-level>]
[-dco|--disable-console-output] [--nologo]
[-?|-h|--help]
```

### Arguments
Expand Down Expand Up @@ -100,6 +103,14 @@ dotnet-coverage merge

Sets the log level. Supported values: `Error`, `Info`, and `Verbose`.

* **`-dco|--disable-console-output`**

Disables console output.

* **`--nologo`**

Do not display Code Coverage banner.

## dotnet-coverage collect

The `collect` command is used to collect code coverage data for any .NET process and its subprocesses. For example, you can collect code coverage data for a console application or a Blazor application. This command supports dynamic and static instrumentation. Static instrumentation is available on all platforms. You can specify files to be statically instrumented using `include-files` option. Dynamic instrumentation is available on Windows (x86, x64 and Arm64), Linux (x64), and macOS (x64). The command supports only .NET modules. Native modules are not supported.
Expand All @@ -114,11 +125,12 @@ The `collect` command will collect code coverage for the given process executed

```console
dotnet-coverage collect
<command> <args>...
[-s|--settings <settings>] [-id|--session-id <session-id>]
[-if|--include-files <include-files>] [-o|--output <output>]
[-f|--output-format <output-format>] [-l|--log-file <log-file>]
[-ll|--log-level <log-level>] [-?|-h|--help]
<command> <args>
[-if|--include-files <include-files>] [-o|--output <output>] [-f|--output-format <output-format>]
[-l|--log-file <log-file>] [-ll|--log-level <log-level>]
[-dco|--disable-console-output] [--nologo]
[-?|-h|--help]
```

#### Server Mode
Expand All @@ -129,9 +141,10 @@ The `collect` command hosts a server for code coverage collection. Clients can c
dotnet-coverage collect
[-s|--settings <settings>] [-id|--session-id <session-id>]
[-sv|--server-mode] [-b|--background] [-t|--timeout]
[-if|--include-files <include-files>] [-o|--output <output>]
[-f|--output-format <output-format>] [-l|--log-file <log-file>]
[-ll|--log-level <log-level>] [-?|-h|--help]
[-if|--include-files <include-files>] [-o|--output <output>] [-f|--output-format <output-format>]
[-l|--log-file <log-file>] [-ll|--log-level <log-level>]
[-dco|--disable-console-output] [--nologo]
[-?|-h|--help]
```

### Arguments
Expand Down Expand Up @@ -186,6 +199,14 @@ dotnet-coverage collect

Sets the log level. Supported values: `Error`, `Info`, and `Verbose`.

* **`-dco|--disable-console-output`**

Disables console output.

* **`--nologo`**

Do not display Code Coverage banner.

## dotnet-coverage connect

The `connect` command is used to connect with the existing server and collects code coverage data for any .NET process and its subprocesses. For example, you can collect code coverage data for a console application or a Blazor application. The command supports only .NET modules. Native modules are not supported.
Expand All @@ -197,10 +218,11 @@ The `connect` command is used to connect with the existing server and collects c

```console
dotnet-coverage connect
<session> <command> <args>...
[-b|--background] [-t|--timeout]
[-l|--log-file <log-file>] [-ll|--log-level <log-level>] [-?|-h|--help]
<session>
<command> <args>
[-l|--log-file <log-file>] [-ll|--log-level <log-level>]
[-dco|--disable-console-output] [--nologo]
[-?|-h|--help]
```

### Arguments
Expand Down Expand Up @@ -235,6 +257,14 @@ dotnet-coverage connect

Sets the log level. Supported values: `Error`, `Info`, and `Verbose`.

* **`-dco|--disable-console-output`**

Disables console output.

* **`--nologo`**

Do not display Code Coverage banner.

## dotnet-coverage snapshot

Creates a coverage file for existing code coverage collection.
Expand All @@ -243,12 +273,14 @@ Creates a coverage file for existing code coverage collection.

```console
dotnet-coverage snapshot
<session>
[-r|--reset]
[-o|--output <output>]
[-tn|--tag-name <tag-name>] [-tid|--tag-identifier <tag-identifier>]
[-o|--output <output>]
[-t|--timeout]
[-l|--log-file <log-file>] [-ll|--log-level <log-level>] [-?|-h|--help]
<session>
[-l|--log-file <log-file>] [-ll|--log-level <log-level>]
[-dco|--disable-console-output] [--nologo]
[-?|-h|--help]
```

### Arguments
Expand All @@ -263,10 +295,6 @@ dotnet-coverage snapshot

Clears existing coverage information after a coverage file is created.

* **`-o|--output <output>`**

Sets the code coverage report output file. If not provided, it's generated automatically with a timestamp.

* **`-tn|--tag-name <tag-name>`**

Creates a snapshot tag name in the coverage file with current coverage information. Tag-name and tag-identifier are mutually inclusive.
Expand All @@ -275,6 +303,10 @@ dotnet-coverage snapshot

Creates a snapshot tag identifier in the coverage file with current coverage information. Tag-name and tag-identifier are mutually inclusive.

* **`-o|--output <output>`**

Sets the code coverage report output file. If not provided, it's generated automatically with a timestamp.

* **`-t|--timeout`**

Timeout (in milliseconds) for interprocess communication between the client and the server.
Expand All @@ -287,6 +319,14 @@ dotnet-coverage snapshot

Sets the log level. Supported values: `Error`, `Info`, and `Verbose`.

* **`-dco|--disable-console-output`**

Disables console output.

* **`--nologo`**

Do not display Code Coverage banner.

## dotnet-coverage shutdown

Closes existing code coverage collection.
Expand All @@ -295,9 +335,11 @@ Closes existing code coverage collection.

```console
dotnet-coverage shutdown
[-t|--timeout]
[-l|--log-file <log-file>] [-ll|--log-level <log-level>] [-?|-h|--help]
<session>
[-t|--timeout]
[-l|--log-file <log-file>] [-ll|--log-level <log-level>]
[-dco|--disable-console-output] [--nologo]
[-?|-h|--help]
```

### Arguments
Expand All @@ -320,6 +362,14 @@ dotnet-coverage shutdown

Sets the log level. Supported values: `Error`, `Info`, and `Verbose`.

* **`-dco|--disable-console-output`**

Disables console output.

* **`--nologo`**

Do not display Code Coverage banner.

## dotnet-coverage instrument

The instrument command is used to instrument binary on disk.
Expand All @@ -328,10 +378,12 @@ The instrument command is used to instrument binary on disk.

```console
dotnet-coverage instrument
[-s|--settings <settings>] [-id|--session-id <session-id>]
[-o|--output <output>] [-l|--log-file <log-file>]
[-ll|--log-level <log-level>] [-?|-h|--help]
<input-file>
[-s|--settings <settings>] [-id|--session-id <session-id>]
[-o|--output <output>]
[-l|--log-file <log-file>] [-ll|--log-level <log-level>]
[-dco|--disable-console-output] [--nologo]
[-?|-h|--help]
```

### Arguments
Expand Down Expand Up @@ -362,6 +414,57 @@ dotnet-coverage instrument

Sets the log level. Supported values: `Error`, `Info`, and `Verbose`.

* **`-dco|--disable-console-output`**

Disables console output.

* **`--nologo`**

Do not display Code Coverage banner.

## dotnet-coverage uninstrument

The uninstrument command is used to restore original binary from the instrumented binary.

### Synopsis

```console
Microsoft.CodeCoverage.Console uninstrument
<input-file>
[-s|--settings <settings>]
[-l|--log-file <log-file>] [-ll|--log-level <log-level>]
[-dco|--disable-console-output] [--nologo]
[-?|-h|--help]
```

### Arguments

* **`<input-file>`**

The input instrumented binary.

### Options

* **`-s|--settings <settings>`**

Sets the path to the XML code coverage settings.

* **`-l|--log-file <log-file>`**

Sets the log file path. When you provide a directory (with a path separator at the end), a new log file is generated for each process under analysis.

* **`-ll|--log-level <log-level>`**

Sets the log level. Supported values: `Error`, `Info`, and `Verbose`.

* **`-dco|--disable-console-output`**

Disables console output.

* **`--nologo`**

Do not display Code Coverage banner.

## Sample scenarios

## Collecting code coverage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ This article list and explains all `Microsoft Testing Platform` extensions relat

You can use the code coverage feature to determine what proportion of your project's code is being tested by coded tests such as unit tests. To effectively guard against bugs, your tests should exercise or *cover* a large proportion of your code.

## Coverlet

There's currently no Coverlet extension, but you can use [Coverlet .NET global tool](https://github.com/coverlet-coverage/coverlet#net-global-tool-guide-suffers-from-possible-known-issue).

## Microsoft code coverage

Microsoft Code Coverage analysis is possible for both managed (CLR) and unmanaged (native) code. Both static and dynamic instrumentation are supported. This extension is shipped as part of [Microsoft.Testing.Extensions.CodeCoverage](https://nuget.org/packages/Microsoft.Testing.Extensions.CodeCoverage) NuGet package.
Expand All @@ -39,3 +35,7 @@ Microsoft Code Coverage provides the following options:
| `--coverage-settings` | XML code coverage settings. |

For more information about the available options, see [settings](../additional-tools/dotnet-coverage.md#settings) and [samples](https://github.com/microsoft/codecoverage/tree/main/samples/Algorithms).

## Coverlet

There's currently no Coverlet extension, but you can use [Coverlet .NET global tool](https://github.com/coverlet-coverage/coverlet#net-global-tool-guide-suffers-from-possible-known-issue).
8 changes: 4 additions & 4 deletions docs/core/tools/dotnet-test.md
Original file line number Diff line number Diff line change
Expand Up @@ -272,16 +272,16 @@ Where `Microsoft.NET.Test.Sdk` is the test host, `xunit` is the test framework.
dotnet test --logger trx
```

- Run the tests in the project in the current directory, and generate a code coverage file (after installing [Coverlet](https://github.com/coverlet-coverage/coverlet/blob/master/Documentation/VSTestIntegration.md) collectors integration):
- Run the tests in the project in the current directory, and generate a code coverage file using [Microsoft Code Coverage](https://github.com/microsoft/codecoverage/blob/main/README.md):

```dotnetcli
dotnet test --collect:"XPlat Code Coverage"
dotnet test --collect "Code Coverage"
```

- Run the tests in the project in the current directory, and generate a code coverage file (Windows only):
- Run the tests in the project in the current directory, and generate a code coverage file using [Coverlet](https://github.com/coverlet-coverage/coverlet/blob/master/README.md) (after installing [Coverlet](https://github.com/coverlet-coverage/coverlet/blob/master/Documentation/VSTestIntegration.md) collectors integration):

```dotnetcli
dotnet test --collect "Code Coverage"
dotnet test --collect:"XPlat Code Coverage"
```

- Run the tests in the project in the current directory, and log with detailed verbosity to the console:
Expand Down
Loading