Skip to content

Commit 95fab55

Browse files
fhnaseerfaisal
andauthored
Updating code coverage documentation (#155)
* Upgrading versions, * Correct target framework * Upgrading dotnet version in yml files, * Fixing warnings related to markdown, * updating docs, * more, --------- Co-authored-by: faisal <faisalhafeez@microsoft.com>
1 parent bfdb0cc commit 95fab55

44 files changed

Lines changed: 357 additions & 305 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,15 @@ Microsoft code coverage functionality is closed source. This repository contains
55
## Get started
66

77
To collect code coverage for .NET test project you can simply execute:
8+
89
```shell
910
dotnet new mstest -o mstests
1011
cd mstests
1112
dotnet test --collect "Code Coverage;Format=cobertura"
1213
```
14+
1315
You should see output:
16+
1417
```shell
1518
Determining projects to restore...
1619
All projects are up-to-date for restore.
@@ -29,6 +32,7 @@ Attachments:
2932
```
3033

3134
For any .NET application you can collect code coverage in this way:
35+
3236
```shell
3337
dotnet new console -o sample1
3438
cd sample1
@@ -37,32 +41,35 @@ dotnet-coverage collect "dotnet run"
3741
```
3842

3943
You should see output:
44+
4045
```shell
41-
Microsoft (R) Code Coverage Command Line Tool (x64)
42-
Copyright (c) Microsoft Corporation. All rights reserved.
46+
dotnet-coverage v17.13.1.0 [win-x64 - .NET 9.0.2]
4347

4448
SessionId: d1bf31db-f634-4b2c-a627-c708ac93d85b
4549
Hello, World!
4650
Code coverage results: output.coverage.
4751
```
4852

4953
For existing projects to get latest features and best performance please keep up to date below references:
54+
5055
```xml
51-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
52-
<PackageReference Include="Microsoft.CodeCoverage" Version="17.12.0" />
56+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.13.0" />
57+
<PackageReference Include="Microsoft.CodeCoverage" Version="17.13.0" />
5358
```
5459

5560
If your solution doesn't contain any C++ code it is recommended to disable native code coverage by adding into configuration below flags:
61+
5662
```xml
5763
<EnableStaticNativeInstrumentation>False</EnableStaticNativeInstrumentation>
5864
<EnableDynamicNativeInstrumentation>False</EnableDynamicNativeInstrumentation>
5965
```
66+
6067
Check other configuration options [here](docs/configuration.md).
6168

62-
## Documentation
69+
## Documentation
6370

64-
* Documentation for `dotnet-coverage` tool is available at https://aka.ms/dotnet-coverage.
65-
* Documentation for `Microsoft.CodeCoverage` is available at https://learn.microsoft.com/visualstudio/test/customizing-code-coverage-analysis
71+
* Documentation for `dotnet-coverage` tool is available [here](https://aka.ms/dotnet-coverage).
72+
* Documentation for `Microsoft.CodeCoverage` is available [here](https://learn.microsoft.com/visualstudio/test/customizing-code-coverage-analysis)
6673
* [Supported OS versions](docs/supported-os.md)
6774
* [Configuration](docs/configuration.md)
6875
* [Performance data](/docs/performance/README.md)
@@ -77,7 +84,7 @@ Check other configuration options [here](docs/configuration.md).
7784

7885
This project welcomes contributions and suggestions. Most contributions require you to agree to a
7986
Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us
80-
the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.
87+
the rights to use your contribution. For details, visit [Contributor License Agreements](https://opensource.microsoft.com/cla/).
8188

8289
When you submit a pull request, a CLA bot will automatically determine whether you need to provide
8390
a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions
@@ -89,8 +96,8 @@ contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additio
8996

9097
## Trademarks
9198

92-
This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft
93-
trademarks or logos is subject to and must follow
99+
This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft
100+
trademarks or logos is subject to and must follow
94101
[Microsoft's Trademark & Brand Guidelines](https://www.microsoft.com/en-us/legal/intellectualproperty/trademarks/usage/general).
95102
Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship.
96103
Any use of third-party trademarks or logos are subject to those third-party's policies.

docs/configuration.md

Lines changed: 48 additions & 45 deletions
Large diffs are not rendered by default.

docs/instrumentation.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ Therefore, in version [17.5.0](https://www.nuget.org/packages/Microsoft.CodeCove
88

99
Dynamic instrumentation necessitates configuring environment variables (CLR Profiling) for code coverage collection. In environments where this isn't feasible, such as in IIS, we recommend opting for static instrumentation.
1010

11-
1211
You can control dynamic and static instrumentation using below flags in your configuration:
12+
1313
```xml
1414
<CodeCoverage>
1515
<EnableDynamicManagedInstrumentation>True</EnableDynamicManagedInstrumentation>
@@ -24,7 +24,8 @@ As we mentioned above when static instrumentation is enabled libraries and corre
2424
<EnableStaticManagedInstrumentationRestore>False</EnableStaticManagedInstrumentationRestore>
2525
</CodeCoverage>
2626
```
27-
It can be useful when debugging some issues or to speed up build inside pipeline.
27+
28+
It can be useful when debugging some issues or to speed up build inside pipeline.
2829

2930
> **_NOTE:_** Make sure instrumented binaries are not deployed into production.
3031

docs/performance/README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# Code coverage performance results
2+
13
Project name | Configuration | No code coverage | Code coverage 16.5 | Code coverage 17.0 | Code coverage 17.5 | Code coverage 17.9
24
-------------|---------------------------|----------|----------|----------|----------|---------
35
InteractiveHost UnitTests | net8.0 Debug | 129.82s | 361.82s (+178.70%) | 278.19s (+114.28%) | 266.49s (+105.27%) | 188.61s (+45.28%)
@@ -100,8 +102,7 @@ VBCSCompiler UnitTests | net472 Debug | 58.47s | 87.00s (+48.80%) | 75.98s (+29.
100102
VBCSCompiler UnitTests | net472 Release | 52.65s | 82.66s (+56.99%) | 71.18s (+35.18%) | 65.19s (+23.80%) | 60.04s (+14.02%)
101103
VBCSCompiler UnitTests | net8.0 Debug | 30.34s | 52.15s (+71.85%) | 47.68s (+57.12%) | 42.01s (+38.44%) | 39.00s (+28.52%)
102104
VBCSCompiler UnitTests | net8.0 Release | 29.26s | 48.75s (+66.62%) | 45.37s (+55.06%) | 39.92s (+36.45%) | 36.80s (+25.78%)
103-
**Total** | | **11520.27s** | **25493.41s (+121.29%)** | **20270.25s (+75.95%)** | **16792.62s (+45.77%)** | **14520.69s (+26.04%)**
104-
105+
**Total** | | **11520.27s** | **25493.41s (+121.29%)** | **20270.25s (+75.95%)** | **16792.62s (+45.77%)** | **14520.69s (+26.04%)**
105106

106107
Package | Time | Ratio
107108
--------|------|------

docs/supported-os.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,4 @@ Other operating systems are supported at best effort.
3333

3434
On macOS and linux dynamic instrumentation requires [libxml2](https://github.com/GNOME/libxml2) package to be installed.
3535

36-
On Alpine 3.18+ dynamic instrumentation requires [libintl](https://pkgs.alpinelinux.org/package/edge/main/x86/libintl) package to be installed.
36+
On Alpine 3.18+ dynamic instrumentation requires [libintl](https://pkgs.alpinelinux.org/package/edge/main/x86/libintl) package to be installed.

samples/Algorithms/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
# Solution summary
22

33
Solution contains two projects:
4+
45
1. `Algorithms.Core` - contains core logic for solution
56
2. `Algorithms.Console` - contains Native AOT console app
67
3. `Algorithms.Core.Tests` - contains unit tests for `Algorithms.Core`. It is [MSTest runner project](https://learn.microsoft.com/en-us/dotnet/core/testing/unit-testing-mstest-runner-intro?tabs=dotnetcli)
78
4. `Algorithms.Core.MSTest.Sdk.Tests` - contains unit tests for `Algorithms.Core`. It is [MSTest runner project using MSTest SDK](https://learn.microsoft.com/en-us/dotnet/core/testing/unit-testing-mstest-sdk)
89

9-
# Scenarios
10+
## Scenarios
1011

1112
1. [***Scenario 01*** Code coverage for MSTest Runner project using dynamic instrumentation](scenarios/scenario01/README.md)
1213
2. [***Scenario 02*** Code coverage for MSTest Runner project using static instrumentation](scenarios/scenario02/README.md)

samples/Algorithms/scenarios/scenario01/README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Collect code coverage using dynamic instrumentation for MSTest runner project.
44

55
> **_NOTE:_** MSTest runner project coverage extension by default is not collecting native code coverage. If you want to enable please set to `True` `EnableStaticNativeInstrumentation` or `EnableDynamicNativeInstrumentation` in configuration.
66
7-
# Collect code coverage using command line
7+
## Collect code coverage using command line
88

99
```shell
1010
git clone https://github.com/microsoft/codecoverage.git
@@ -14,7 +14,7 @@ dotnet run --coverage --coverage-output report.cobertura.xml --coverage-output-f
1414

1515
You can also use [run.ps1](run.ps1) to collect code coverage.
1616

17-
# Collect code coverage inside github workflow
17+
## Collect code coverage inside github workflow
1818

1919
`reportgenerator` can be used to generate final github summary markdown.
2020

@@ -40,17 +40,18 @@ You can also use [run.ps1](run.ps1) to collect code coverage.
4040
- name: Upload coverage into summary
4141
run: cat $GITHUB_WORKSPACE/coveragereport/SummaryGithub.md >> $GITHUB_STEP_SUMMARY
4242
- name: Archive code coverage results
43-
uses: actions/upload-artifact@v3
43+
uses: actions/upload-artifact@v4
4444
with:
4545
name: code-coverage-report
4646
path: ${{ github.workspace }}/report.cobertura.xml
47+
overwrite: true
4748
```
4849
4950
[Full source example](../../../../.github/workflows/Algorithms_Scenario01.yml)
5051
5152
[Run example](../../../../../../actions/workflows/Algorithms_Scenario01.yml)
5253
53-
# Collect code coverage inside Azure DevOps Pipelines
54+
## Collect code coverage inside Azure DevOps Pipelines
5455
5556
```yml
5657
steps:
@@ -89,8 +90,8 @@ steps:
8990
9091
![alt text](azure-pipelines.jpg "Code Coverage tab in Azure DevOps pipelines")
9192
92-
# Report example
93+
## Report example
9394
9495
![alt text](example.report.jpg "Example report")
9596
96-
[Link](example.report.cobertura.xml)
97+
[Link](example.report.cobertura.xml)

samples/Algorithms/scenarios/scenario02/README.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Collect code coverage using static instrumentation for MSTest runner project. As
44

55
> **_NOTE:_** MSTest runner project coverage extension by default is not collecting native code coverage. If you want to enable please set to `True` `EnableStaticNativeInstrumentation` or `EnableDynamicNativeInstrumentation` in configuration.
66
7-
# Configuration
7+
## Configuration
88

99
```xml
1010
<?xml version="1.0" encoding="utf-8"?>
@@ -17,7 +17,7 @@ Collect code coverage using static instrumentation for MSTest runner project. As
1717
</Configuration>
1818
```
1919

20-
# Collect code coverage using command line
20+
## Collect code coverage using command line
2121

2222
```shell
2323
git clone https://github.com/microsoft/codecoverage.git
@@ -27,7 +27,7 @@ dotnet run --coverage --coverage-output report.cobertura.xml --coverage-output-f
2727

2828
You can also use [run.ps1](run.ps1) to collect code coverage.
2929

30-
# Collect code coverage inside github workflow
30+
## Collect code coverage inside github workflow
3131

3232
`reportgenerator` can be used to generate final github summary markdown.
3333

@@ -53,17 +53,18 @@ You can also use [run.ps1](run.ps1) to collect code coverage.
5353
- name: Upload coverage into summary
5454
run: cat $GITHUB_WORKSPACE/coveragereport/SummaryGithub.md >> $GITHUB_STEP_SUMMARY
5555
- name: Archive code coverage results
56-
uses: actions/upload-artifact@v3
56+
uses: actions/upload-artifact@v4
5757
with:
5858
name: code-coverage-report
5959
path: ${{ github.workspace }}/report.cobertura.xml
60+
overwrite: true
6061
```
6162
6263
[Full source example](../../../../.github/workflows/Algorithms_Scenario02.yml)
6364
6465
[Run example](../../../../../../actions/workflows/Algorithms_Scenario02.yml)
6566
66-
# Collect code coverage inside Azure DevOps Pipelines
67+
## Collect code coverage inside Azure DevOps Pipelines
6768
6869
```yml
6970
steps:
@@ -102,8 +103,8 @@ steps:
102103
103104
![alt text](azure-pipelines.jpg "Code Coverage tab in Azure DevOps pipelines")
104105
105-
# Report example
106+
## Report example
106107
107108
![alt text](example.report.jpg "Example report")
108109
109-
[Link](example.report.cobertura.xml)
110+
[Link](example.report.cobertura.xml)

samples/Algorithms/scenarios/scenario03/README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Collect code coverage using compile-time instrumentation for MSTest runner proje
44

55
> **_NOTE:_** MSTest runner project coverage extension by default is not collecting native code coverage. If you want to enable please set to `True` `EnableStaticNativeInstrumentation` or `EnableDynamicNativeInstrumentation` in configuration.
66
7-
# Collect code coverage using command line
7+
## Collect code coverage using command line
88

99
```shell
1010
git clone https://github.com/microsoft/codecoverage.git
@@ -15,7 +15,7 @@ dotnet run --no-build --coverage --coverage-output report.cobertura.xml --covera
1515

1616
You can also use [run.ps1](run.ps1) to collect code coverage.
1717

18-
# Collect code coverage inside github workflow
18+
## Collect code coverage inside github workflow
1919

2020
`reportgenerator` can be used to generate final github summary markdown.
2121

@@ -41,17 +41,18 @@ You can also use [run.ps1](run.ps1) to collect code coverage.
4141
- name: Upload coverage into summary
4242
run: cat $GITHUB_WORKSPACE/coveragereport/SummaryGithub.md >> $GITHUB_STEP_SUMMARY
4343
- name: Archive code coverage results
44-
uses: actions/upload-artifact@v3
44+
uses: actions/upload-artifact@v4
4545
with:
4646
name: code-coverage-report
4747
path: ${{ github.workspace }}/report.cobertura.xml
48+
overwrite: true
4849
```
4950
5051
[Full source example](../../../../.github/workflows/Algorithms_Scenario03.yml)
5152
5253
[Run example](../../../../../../actions/workflows/Algorithms_Scenario03.yml)
5354
54-
# Collect code coverage inside Azure DevOps Pipelines
55+
## Collect code coverage inside Azure DevOps Pipelines
5556
5657
```yml
5758
steps:
@@ -85,8 +86,8 @@ steps:
8586
8687
![alt text](azure-pipelines.jpg "Code Coverage tab in Azure DevOps pipelines")
8788
88-
# Report example
89+
## Report example
8990
9091
![alt text](example.report.jpg "Example report")
9192
92-
[Link](example.report.cobertura.xml)
93+
[Link](example.report.cobertura.xml)

samples/Algorithms/scenarios/scenario04/README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Collect code coverage using `dotnet-coverage` tool for MSTest runner project.
44

55
> **_NOTE:_** MSTest runner project coverage extension by default is not collecting native code coverage. If you want to enable please set to `True` `EnableStaticNativeInstrumentation` or `EnableDynamicNativeInstrumentation` in configuration.
66
7-
# Collect code coverage using command line
7+
## Collect code coverage using command line
88

99
```shell
1010
git clone https://github.com/microsoft/codecoverage.git
@@ -16,7 +16,7 @@ dotnet-coverage collect --output report.cobertura.xml --output-format cobertura
1616

1717
You can also use [run.ps1](run.ps1) to collect code coverage.
1818

19-
# Collect code coverage inside github workflow
19+
## Collect code coverage inside github workflow
2020

2121
`reportgenerator` can be used to generate final github summary markdown.
2222

@@ -44,17 +44,18 @@ You can also use [run.ps1](run.ps1) to collect code coverage.
4444
- name: Upload coverage into summary
4545
run: cat $GITHUB_WORKSPACE/coveragereport/SummaryGithub.md >> $GITHUB_STEP_SUMMARY
4646
- name: Archive code coverage results
47-
uses: actions/upload-artifact@v3
47+
uses: actions/upload-artifact@v4
4848
with:
4949
name: code-coverage-report
5050
path: ${{ github.workspace }}/report.cobertura.xml
51+
overwrite: true
5152
```
5253
5354
[Full source example](../../../../.github/workflows/Algorithms_Scenario04.yml)
5455
5556
[Run example](../../../../../../actions/workflows/Algorithms_Scenario04.yml)
5657
57-
# Collect code coverage inside Azure DevOps Pipelines
58+
## Collect code coverage inside Azure DevOps Pipelines
5859
5960
```yml
6061
steps:
@@ -99,8 +100,8 @@ steps:
99100
100101
![alt text](azure-pipelines.jpg "Code Coverage tab in Azure DevOps pipelines")
101102
102-
# Report example
103+
## Report example
103104
104105
![alt text](example.report.jpg "Example report")
105106
106-
[Link](example.report.cobertura.xml)
107+
[Link](example.report.cobertura.xml)

0 commit comments

Comments
 (0)