You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Update project for .NET 8.0 and improve documentation
- Add notable changes section in `Changelog.md` for .NET 8.0 LTS upgrade and xUnit updates.
- Revise `HowTo.md` for prerequisites on deterministic builds and local NuGet package generation.
- Modify `KnownIssues.md` for assembly resolution behavior and `CopyLocalLockFileAssemblies`.
- Update `ReleasePlan.md` with new package versions for `coverlet.msbuild` and `coverlet.collector`.
- Revise `Troubleshooting.md` for output directory changes and local build instructions.
- Update `VSTestIntegration.md` for new minimum version requirements for .NET SDK and `coverlet.collector`.
- Update CI configuration files to install .NET SDK version 8.0.411.
- Update `global.json` to specify .NET SDK version 8.0.411.
To run test we need to generates packages to reference in on test project.
2
-
Run from repo root
1
+
# Using Deterministic Builds with Coverlet MSBuild Integration
2
+
3
+
## Prerequisites
4
+
5
+
Before running tests with deterministic builds, you need to generate the local NuGet packages:
3
6
4
7
```shell
5
-
C:\git\coverlet
6
-
λ dotnet pack
7
-
Microsoft (R) Build Engine version 17.7.4+3ebbd7c49 for .NET Core
8
-
Copyright (C) Microsoft Corporation. All rights reserved.
9
-
10
-
Restore completed in 73,36 ms for C:\git\coverlet\src\coverlet.core\coverlet.core.csproj.
11
-
Restore completed in 73,41 ms for C:\git\coverlet\test\coverlet.testsubject\coverlet.testsubject.csproj.
12
-
Restore completed in 73,33 ms for C:\git\coverlet\test\coverlet.tests.projectsample.excludedbyattribute\coverlet.tests.projectsample.excludedbyattribute.csproj.
13
-
Restore completed in 73,34 ms for C:\git\coverlet\src\coverlet.collector\coverlet.collector.csproj.
14
-
Restore completed in 73,35 ms for C:\git\coverlet\test\coverlet.tests.xunit.extensions\coverlet.tests.xunit.extensions.csproj.
15
-
Restore completed in 75,92 ms for C:\git\coverlet\test\coverlet.integration.tests\coverlet.integration.tests.csproj.
16
-
Restore completed in 73,41 ms for C:\git\coverlet\src\coverlet.console\coverlet.console.csproj.
17
-
Restore completed in 73,36 ms for C:\git\coverlet\test\coverlet.tests.projectsample.empty\coverlet.tests.projectsample.empty.csproj.
18
-
Restore completed in 73,47 ms for C:\git\coverlet\src\coverlet.msbuild.tasks\coverlet.msbuild.tasks.csproj.
19
-
Restore completed in 73,37 ms for C:\git\coverlet\test\coverlet.core.tests.samples.netstandard\coverlet.core.tests.samples.netstandard.csproj.
20
-
Restore completed in 76,37 ms for C:\git\coverlet\test\coverlet.collector.tests\coverlet.collector.tests.csproj.
21
-
Restore completed in 77,05 ms for C:\git\coverlet\test\coverlet.integration.template\coverlet.integration.template.csproj.
22
-
Restore completed in 77,2 ms for C:\git\coverlet\test\coverlet.core.performancetest\coverlet.core.performancetest.csproj.
23
-
Restore completed in 87,7 ms for C:\git\coverlet\test\coverlet.core.tests\coverlet.core.tests.csproj.
λ dotnet test /p:CollectCoverage=true /p:DeterministicSourcePaths=true
72
-
Test run for C:\git\coverlet\Documentation\Examples\MSBuild\DeterministicBuild\XUnitTestProject1\bin\Debug\net6.0\XUnitTestProject1.dll(.NETCoreApp,Version=v6.0)
73
-
Microsoft (R) Test Execution Command Line Tool Version 17.5.0
74
-
Copyright (c) Microsoft Corporation. All rights reserved.
75
-
76
-
Starting test execution, please wait...
77
-
78
-
A total of 1 test files matched the specified pattern.
dotnet test /p:CollectCoverage=true /p:DeterministicSourcePaths=true
101
49
```
102
50
103
-
You should see on output folder the coverlet source root mapping file generated. The filename starts with 'CoverletSourceRootsMapping_'. Do not use `--no-build` option
104
-
This is the confirmation that you're running coverage on deterministic build e.g. `Documentation\Examples\MSBuild\DeterministicBuild\XUnitTestProject1\bin\Debug\net6.0\CoverletSourceRootsMapping_XUnitTestProject1`
51
+
> **Important**: Do not use the `--no-build` option as it will prevent the generation of deterministic build artifacts.
105
52
53
+
## Verification
54
+
55
+
After running the tests, verify the deterministic build by checking for the source root mapping file:
To merge report together you need to run separate test and merge in one `json` format file.
4
-
Last command will join and create final needed format file.
3
+
## Running Tests Separately
5
4
6
-
```shell
7
-
dotnet test XUnitTestProject1\XUnitTestProject1.csproj /p:CollectCoverage=true /p:CoverletOutput=../CoverageResults/
8
-
dotnet test XUnitTestProject2\XUnitTestProject2.csproj /p:CollectCoverage=true /p:CoverletOutput=../CoverageResults/ /p:MergeWith="../CoverageResults/coverage.json"
9
-
dotnet test XUnitTestProject3\XUnitTestProject3.csproj /p:CollectCoverage=true /p:CoverletOutput=../CoverageResults/ /p:MergeWith="../CoverageResults/coverage.json" /p:CoverletOutputFormat="opencover"
5
+
To merge coverage reports, run tests for each project and combine them into a single file:
6
+
7
+
```bash
8
+
# Generate coverage for first project
9
+
dotnet test XUnitTestProject1/XUnitTestProject1.csproj \
10
+
/p:CollectCoverage=true \
11
+
/p:CoverletOutput=../CoverageResults/
12
+
13
+
# Merge coverage from second project
14
+
dotnet test XUnitTestProject2/XUnitTestProject2.csproj \
15
+
/p:CollectCoverage=true \
16
+
/p:CoverletOutput=../CoverageResults/ \
17
+
/p:MergeWith="../CoverageResults/coverage.json"
18
+
19
+
# Merge coverage from third project and generate final OpenCover report
20
+
dotnet test XUnitTestProject3/XUnitTestProject3.csproj \
21
+
/p:CollectCoverage=true \
22
+
/p:CoverletOutput=../CoverageResults/ \
23
+
/p:MergeWith="../CoverageResults/coverage.json" \
24
+
/p:CoverletOutputFormat="opencover"
10
25
```
11
26
12
-
You can merge also running `dotnet test` and merge with single command from a solution file, but you need to ensure that tests will run sequentially(`-m:1`). This slow down testing but avoid invalid coverage result.
27
+
## Running Tests from Solution
13
28
14
-
```shell
15
-
dotnet test /p:CollectCoverage=true /p:CoverletOutput=../CoverageResults/ /p:MergeWith="../CoverageResults/coverage.json" /p:CoverletOutputFormat=\"opencover,json\" -m:1
29
+
To merge coverage using a single command (requires sequential execution):
30
+
31
+
```bash
32
+
dotnet test \
33
+
/p:CollectCoverage=true \
34
+
/p:CoverletOutput=../CoverageResults/ \
35
+
/p:MergeWith="../CoverageResults/coverage.json" \
36
+
/p:CoverletOutputFormat="opencover,json" \
37
+
-m:1
16
38
```
17
39
18
-
N.B. You need to specify `json` format plus another format(the final one), because Coverlet can only merge proprietary format. At the end you can delete temporary `coverage.json` file.
40
+
> **Note**: Sequential execution (`-m:1`) ensures accurate coverage but increases test duration.
41
+
42
+
## Important Considerations
43
+
44
+
- Include `json` format alongside your desired output format
45
+
- Coverlet only merges its proprietary JSON format
46
+
- The temporary `coverage.json` file can be deleted after merging
19
47
20
-
You can also merge the coverage result and generate another valid format to export the content than opencover, like cobertura.
48
+
## Example with Cobertura Output
21
49
22
-
```shell
23
-
dotnet test /p:CollectCoverage=true /p:CoverletOutput=../CoverageResults/ /p:MergeWith="../CoverageResults/coverage.json" /p:CoverletOutputFormat=\"cobertura,json\" -m:1
0 commit comments