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
use .NET 8.0 target framework for coverlet.core and remove Newtonsoft.Json
- Updated project files to target .NET 8.0 instead of .NET 6.0 across various projects.
- Replaced Newtonsoft.Json with System.Text.Json in Coverage.cs and related files for improved performance and reduced dependencies.
- Enhanced JSON serialization in tests and reporters to utilize System.Text.Json.
- Updated integration tests to reflect changes in target frameworks and SDK versions.
- Adjusted test projects to ensure compatibility with the new SDK version and updated dependencies.
- Modified coverlet.collector.targets to support .NET SDK version 8.0.100.
Copy file name to clipboardExpand all lines: Directory.Build.props
-31Lines changed: 0 additions & 31 deletions
Original file line number
Diff line number
Diff line change
@@ -48,35 +48,4 @@
48
48
<VSTestLogger>@(VSTestLogger)</VSTestLogger>
49
49
</PropertyGroup>
50
50
51
-
<PropertyGroup>
52
-
<!--
53
-
Do not change versions since we need to support VSTest DataCollectors. We need to load assembly version 1.6.0 to properly work
54
-
We can check minimum supported package version here https://github.com/Microsoft/vstest/blob/master/src/Microsoft.TestPlatform.ObjectModel/Microsoft.TestPlatform.ObjectModel.csproj#L34
<!-- some additional information about dependency management limitations for MSBuild tasks (coverlet.msbuild.tasks)
63
-
- msBuild task with dependencies https://natemcmaster.com/blog/2017/11/11/msbuild-task-with-dependencies/
64
-
- Aligning versions with MSBuild
65
-
- If you need a dependency that is also used in MSBuild itself, you have to align with the version MSBuild uses.
66
-
- This includes System.Reflection.Metadata, System.Collections.Immutable, NuGet, Newtonsoft.Json, and others.
67
-
- See example: dependencies.props (https://github.com/aspnet/BuildTools/blob/1f3f14382764e06b7e691e5ee89d12a280249284/build/dependencies.props#L19-L29)"
68
-
69
-
.NET 8.0.3xx (MSBuild) core-sdk-tasks version details https://github.com/dotnet/installer/blob/release/8.0.3xx/src/core-sdk-tasks/core-sdk-tasks.csproj
70
-
71
-
ALIGN PACKAGE VERSIONS of coverlet.core with coverlet.collector (vstest) and coverlet.msbuild.tasks (.NET SDK MSBuild)
NuGetFrameworksVersion is defined here https://github.com/microsoft/vstest/blob/9a0c41811637edf4afe0e265e08fdd1cb18109ed/eng/Versions.props#L94C1-L94C1
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