Skip to content

Commit

Permalink
Add coverlet connector
Browse files Browse the repository at this point in the history
- Update VSTest to minimum supported version
- Use the coverlet connector

Due to known issues, the datacollector integration is suggested

See coverlet-coverage/coverlet#1278 (comment)
And https://github.com/coverlet-coverage/coverlet/blob/master/Documentation/VSTestIntegration.md

<!-- Minimum version 16.5.0 -->
  • Loading branch information
andrei-epure-sonarsource committed Jul 27, 2022
1 parent ca721bd commit 1cbfa87
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 22 deletions.
20 changes: 20 additions & 0 deletions analyzers/runsettings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8" ?>
<RunSettings>
<DataCollectionRunSettings>
<DataCollectors>
<DataCollector friendlyName="XPlat code coverage">
<Configuration>
<Format>opencover</Format>
</Configuration>
</DataCollector>
</DataCollectors>
</DataCollectionRunSettings>
<InProcDataCollectionRunSettings>
<InProcDataCollectors>
<InProcDataCollector assemblyQualifiedName="Coverlet.Collector.DataCollection.CoverletInProcDataCollector, coverlet.collector, Version=1.1.0.0, Culture=neutral, PublicKeyToken=null"
friendlyName="XPlat Code Coverage"
enabled="True"
codebase="coverlet.collector.dll" />
</InProcDataCollectors>
</InProcDataCollectionRunSettings>
</RunSettings>
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
-->
<AssetTargetFallback>$(AssetTargetFallback);net40-client;portable-net45+win8+wp8+wpa81;</AssetTargetFallback>
<ProjectGuid>{e11606ca-a186-4fee-ba30-b1688747cd1a}</ProjectGuid>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

<ItemGroup Condition="'$(TargetFramework)' != 'net48'">
Expand All @@ -27,7 +28,16 @@
<ItemGroup>
<PackageReference Include="FluentAssertions" Version="5.10.3" />
<PackageReference Include="FluentAssertions.Analyzers" Version="0.13.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.4.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
<!-- Update this reference when new version is released -->
<PackageReference Include="coverlet.collector" Version="3.1.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="coverlet.msbuild" Version="3.1.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Moq" Version="4.13.1" />
<PackageReference Include="MSTest.TestAdapter" Version="2.0.0" />
<PackageReference Include="MSTest.TestFramework" Version="2.0.0" />
Expand Down
63 changes: 44 additions & 19 deletions analyzers/tests/SonarAnalyzer.UnitTest/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@
"version": 1,
"dependencies": {
".NETFramework,Version=v4.8": {
"coverlet.collector": {
"type": "Direct",
"requested": "[3.1.2, )",
"resolved": "3.1.2",
"contentHash": "wuLDIDKD5XMt0A7lE31JPenT7QQwZPFkP5rRpdJeblyXZ9MGLI8rYjvm5fvAKln+2/X+4IxxQDxBtwdrqKNLZw=="
},
"coverlet.msbuild": {
"type": "Direct",
"requested": "[3.1.2, )",
"resolved": "3.1.2",
"contentHash": "QhM0fnDtmIMImY7oxyQ/kh1VYtRxPyRVeLwRUGuUvI6Xp83pSYG9gerK8WgJj4TzUl7ISziADUGtIWKhtlbkbQ=="
},
"FluentAssertions": {
"type": "Direct",
"requested": "[5.10.3, )",
Expand Down Expand Up @@ -58,11 +70,11 @@
},
"Microsoft.NET.Test.Sdk": {
"type": "Direct",
"requested": "[16.4.0, )",
"resolved": "16.4.0",
"contentHash": "gjjqS3rCzg4DrSQq4YwJwUUvc49HtXpXrZkW9fu5VG+K4X+Ztn4+UzolyML7wPnl/EAIufk4hu628bJB4WtpFg==",
"requested": "[16.11.0, )",
"resolved": "16.11.0",
"contentHash": "f4mbG1SUSkNWF5p7B3Y8ZxMsvKhxCmpZhdl+w6tMtLSUGE7Izi1syU6TkmKOvB2BV66pdbENConFAISOix4ohQ==",
"dependencies": {
"Microsoft.CodeCoverage": "16.4.0"
"Microsoft.CodeCoverage": "16.11.0"
}
},
"Moq": {
Expand Down Expand Up @@ -185,8 +197,8 @@
},
"Microsoft.CodeCoverage": {
"type": "Transitive",
"resolved": "16.4.0",
"contentHash": "qb7PMVZMAY5iUCvB/kDUEt9xqazWKZoKY/sGpAJO4VtwgN5IcEgipCu3n0i1GPCwGbWVL6k4a8a9F+FqmADJng=="
"resolved": "16.11.0",
"contentHash": "wf6lpAeCqP0KFfbDVtfL50lr7jY1gq0+0oSphyksfLOEygMDXqnaxHK5LPFtMEhYSEtgXdNyXNnEddOqQQUdlQ=="
},
"Newtonsoft.Json": {
"type": "Transitive",
Expand Down Expand Up @@ -431,6 +443,18 @@
}
},
"net6.0": {
"coverlet.collector": {
"type": "Direct",
"requested": "[3.1.2, )",
"resolved": "3.1.2",
"contentHash": "wuLDIDKD5XMt0A7lE31JPenT7QQwZPFkP5rRpdJeblyXZ9MGLI8rYjvm5fvAKln+2/X+4IxxQDxBtwdrqKNLZw=="
},
"coverlet.msbuild": {
"type": "Direct",
"requested": "[3.1.2, )",
"resolved": "3.1.2",
"contentHash": "QhM0fnDtmIMImY7oxyQ/kh1VYtRxPyRVeLwRUGuUvI6Xp83pSYG9gerK8WgJj4TzUl7ISziADUGtIWKhtlbkbQ=="
},
"FluentAssertions": {
"type": "Direct",
"requested": "[5.10.3, )",
Expand Down Expand Up @@ -490,12 +514,12 @@
},
"Microsoft.NET.Test.Sdk": {
"type": "Direct",
"requested": "[16.4.0, )",
"resolved": "16.4.0",
"contentHash": "gjjqS3rCzg4DrSQq4YwJwUUvc49HtXpXrZkW9fu5VG+K4X+Ztn4+UzolyML7wPnl/EAIufk4hu628bJB4WtpFg==",
"requested": "[16.11.0, )",
"resolved": "16.11.0",
"contentHash": "f4mbG1SUSkNWF5p7B3Y8ZxMsvKhxCmpZhdl+w6tMtLSUGE7Izi1syU6TkmKOvB2BV66pdbENConFAISOix4ohQ==",
"dependencies": {
"Microsoft.CodeCoverage": "16.4.0",
"Microsoft.TestPlatform.TestHost": "16.4.0"
"Microsoft.CodeCoverage": "16.11.0",
"Microsoft.TestPlatform.TestHost": "16.11.0"
}
},
"Moq": {
Expand Down Expand Up @@ -666,8 +690,8 @@
},
"Microsoft.CodeCoverage": {
"type": "Transitive",
"resolved": "16.4.0",
"contentHash": "qb7PMVZMAY5iUCvB/kDUEt9xqazWKZoKY/sGpAJO4VtwgN5IcEgipCu3n0i1GPCwGbWVL6k4a8a9F+FqmADJng=="
"resolved": "16.11.0",
"contentHash": "wf6lpAeCqP0KFfbDVtfL50lr7jY1gq0+0oSphyksfLOEygMDXqnaxHK5LPFtMEhYSEtgXdNyXNnEddOqQQUdlQ=="
},
"Microsoft.CSharp": {
"type": "Transitive",
Expand Down Expand Up @@ -704,18 +728,19 @@
},
"Microsoft.TestPlatform.ObjectModel": {
"type": "Transitive",
"resolved": "16.4.0",
"contentHash": "4geKywSUJHHrfBTr1wJXUVWP0Vx1X03oFQAdZdGa8jK8p5MSwsJ4Vd0/mqN0dB2YXaIXIhDT94ti5WQ1KZ4jdw==",
"resolved": "16.11.0",
"contentHash": "EiknJx9N9Z30gs7R+HHhki7fA8EiiM3pwD1vkw3bFsBC8kdVq/O7mHf1hrg5aJp+ASO6BoOzQueD2ysfTOy/Bg==",
"dependencies": {
"NuGet.Frameworks": "5.0.0"
"NuGet.Frameworks": "5.0.0",
"System.Reflection.Metadata": "1.6.0"
}
},
"Microsoft.TestPlatform.TestHost": {
"type": "Transitive",
"resolved": "16.4.0",
"contentHash": "tMlz3uc7VUZSYYslyVOVXH40KexTptZMAi8gIE+5w+SIt8I0qLPObpqX6QVLWszPr7sxX4WAKTiFgqgBB1MxjA==",
"resolved": "16.11.0",
"contentHash": "/Q+R0EcCJE8JaYCk+bGReicw/xrB0HhecrYrUcLbn95BnAlaTJrZhoLkUhvtKTAVtqX/AIKWXYtutiU/Q6QUgg==",
"dependencies": {
"Microsoft.TestPlatform.ObjectModel": "16.4.0",
"Microsoft.TestPlatform.ObjectModel": "16.11.0",
"Newtonsoft.Json": "9.0.1"
}
},
Expand Down
30 changes: 28 additions & 2 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,24 @@ stages:
- powershell: |
. .\scripts\utils.ps1
$TestResultsDir = "analyzers\tests\SonarAnalyzer.UnitTest\TestResults\"
if (Test-Path $TestResultsDir) { Remove-Item -Path $TestResultsDir -Recurse -Verbose }
CreateFolder("coverage")
CreateFolder("TestResults")
& OpenCover.Console.exe -target:"dotnet.exe" -targetargs:"test analyzers\tests\SonarAnalyzer.UnitTest\bin\$(BuildConfiguration)\net48\SonarAnalyzer.UnitTest.dll -l trx -l console;verbosity=detailed" -returntargetcode -filter:"+[SonarAnalyzer.CFG]* +[SonarAnalyzer]* +[SonarAnalyzer.CSharp]* +[SonarAnalyzer.Utilities]* +[SonarAnalyzer.VisualBasic]*" -output:coverage/net48.xml -safemode:off -excludebyattribute:*.ExcludeFromCodeCoverageAttribute
gci analyzers\tests\SonarAnalyzer.UnitTest\bin\$(BuildConfiguration)\net48
dotnet test .\analyzers\SonarAnalyzer.sln --no-build --collect:"XPlat Code Coverage" --settings .\analyzers\runsettings.xml -l "trx;logfilename=net48.trx" -l "console;verbosity=diagnostic" -c $(BuildConfiguration) -f net48 -v diag
Test-ExitCode "ERROR: Unit tests for net48 FAILED."
gci -Path $TestResultsDir -Recurse
Get-ChildItem -Path $TestResultsDir -Recurse -File -Filter coverage.opencover.xml | Copy-Item -Verbose -Destination .\coverage\net48.xml
Get-ChildItem -Path $TestResultsDir -Recurse -File -Filter net48.trx | Copy-Item -Verbose -Destination .\TestResults\
### & OpenCover.Console.exe -target:"dotnet.exe" -targetargs:"test analyzers\tests\SonarAnalyzer.UnitTest\bin\$(BuildConfiguration)\net48\SonarAnalyzer.UnitTest.dll -l trx -l console;verbosity=detailed" -returntargetcode -filter:"+[SonarAnalyzer.CFG]* +[SonarAnalyzer]* +[SonarAnalyzer.CSharp]* +[SonarAnalyzer.Utilities]* +[SonarAnalyzer.VisualBasic]*" -output:coverage/net48.xml -safemode:off -excludebyattribute:*.ExcludeFromCodeCoverageAttribute
### Test-ExitCode "ERROR: Unit tests for net48 FAILED."
displayName: '.Net UTs'
- task: PublishPipelineArtifact@1
Expand Down Expand Up @@ -194,11 +207,24 @@ stages:
- powershell: |
. .\scripts\utils.ps1
$TestResultsDir = "analyzers\tests\SonarAnalyzer.UnitTest\TestResults\"
if (Test-Path $TestResultsDir) { Remove-Item -Path $TestResultsDir -Recurse -Verbose }
CreateFolder("coverage")
CreateFolder("TestResults")
& OpenCover.Console.exe -target:"dotnet.exe" -targetargs:"test analyzers\tests\SonarAnalyzer.UnitTest\bin\$(BuildConfiguration)\net6.0\SonarAnalyzer.UnitTest.dll -l trx -l console;verbosity=detailed" -returntargetcode -filter:"+[SonarAnalyzer.CFG]* +[SonarAnalyzer]* +[SonarAnalyzer.CSharp]* +[SonarAnalyzer.Utilities]* +[SonarAnalyzer.VisualBasic]*" -output:coverage/net6.0.xml -safemode:off -excludebyattribute:*.ExcludeFromCodeCoverageAttribute
gci "analyzers\tests\SonarAnalyzer.UnitTest\bin\$(BuildConfiguration)\net6.0"
dotnet test .\analyzers\SonarAnalyzer.sln --no-build --collect:"XPlat Code Coverage" --settings .\analyzers\runsettings.xml -l "trx;logfilename=net6.0.trx" -l "console;verbosity=diagnostic" -c $(BuildConfiguration) -f "net6.0" -v diag
Test-ExitCode "ERROR: Unit tests for net6.0 FAILED."
gci -Path $TestResultsDir -Recurse
Get-ChildItem -Path $TestResultsDir -Recurse -File -Filter coverage.opencover.xml | Copy-Item -Verbose -Destination .\coverage\net6.0.xml
Get-ChildItem -Path $TestResultsDir -Recurse -File -Filter net6.0.trx | Copy-Item -Verbose -Destination .\TestResults\
## & OpenCover.Console.exe -target:"dotnet.exe" -targetargs:"test analyzers\tests\SonarAnalyzer.UnitTest\bin\$(BuildConfiguration)\net6.0\SonarAnalyzer.UnitTest.dll -l trx -l console;verbosity=detailed" -returntargetcode -filter:"+[SonarAnalyzer.CFG]* +[SonarAnalyzer]* +[SonarAnalyzer.CSharp]* +[SonarAnalyzer.Utilities]* +[SonarAnalyzer.VisualBasic]*" -output:coverage/net6.0.xml -safemode:off -excludebyattribute:*.ExcludeFromCodeCoverageAttribute
## Test-ExitCode "ERROR: Unit tests for net6.0 FAILED."
displayName: '.Net UTs'
- task: PublishPipelineArtifact@1
Expand Down

0 comments on commit 1cbfa87

Please sign in to comment.