Skip to content

Commit

Permalink
Use VSTest integration for Coverlet
Browse files Browse the repository at this point in the history
Fixes #15231. Relates to #14427.
  • Loading branch information
heaths committed Nov 17, 2020
1 parent e16d1ff commit e3ed72c
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 8 deletions.
16 changes: 16 additions & 0 deletions eng/CodeCoverage.runsettings
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0"?>
<RunSettings>
<DataCollectionRunSettings>
<DataCollectors>
<DataCollector friendlyName="XPlat code coverage">
<Configuration>
<Format>cobertura</Format>
<ExcludeByAttribute>CompilerGeneratedAttribute,ExcludeFromCodeCoverage,GeneratedCodeAttribute,Obsolete</ExcludeByAttribute>
<SingleHit>false</SingleHit>
<IncludeTestAssembly>false</IncludeTestAssembly>
<SkipAutoProps>true</SkipAutoProps>
</Configuration>
</DataCollector>
</DataCollectors>
</DataCollectionRunSettings>
</RunSettings>
10 changes: 6 additions & 4 deletions eng/CodeCoverage.targets
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
<Project>
<ItemGroup Condition="'$(IsTestProject)' == 'true'">
<PackageReference Include="coverlet.msbuild">
<PackageReference Include="coverlet.collector">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
</ItemGroup>

<!-- Allows Collection of Code Coverage for Deterministic Builds
https://github.com/coverlet-coverage/coverlet/blob/master/Documentation/DeterministicBuild.md -->
<!--
Allows Collection of Code Coverage for Deterministic Builds
https://github.com/coverlet-coverage/coverlet/blob/master/Documentation/DeterministicBuild.md
-->
<ItemGroup>
<SourceRoot Include="$(NuGetPackageRoot)" />
</ItemGroup>
Expand All @@ -20,4 +22,4 @@
<_LocalTopLevelSourceRoot Include="@(SourceRoot)" Condition="'%(SourceRoot.NestedRoot)' == ''"/>
</ItemGroup>
</Target>
</Project>
</Project>
13 changes: 12 additions & 1 deletion eng/Directory.Build.Data.props
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
<GenerateAPIListing Condition="'$(IsShippingClientLibrary)' == 'true'">true</GenerateAPIListing>
<UpdateSourceOnBuild Condition="'$(UpdateSourceOnBuild)' == ''">$(AZURE_DEV_UPDATESOURCESONBUILD)</UpdateSourceOnBuild>
<PowerShellExe Condition="'$(PowerShellExe)' == ''">pwsh</PowerShellExe>
<CoverletOutputFormat Condition="'$(CoverletOutputFormat)' == '' and '$(CollectCoverage)' == 'true'">cobertura</CoverletOutputFormat>
</PropertyGroup>

<PropertyGroup Condition="'$(IsShippingClientLibrary)' == 'true' and '$(TF_BUILD)' == 'true'">
Expand All @@ -73,6 +72,18 @@
<CodeAnalysisRuleSet>$(RepoEngPath)\CodeAnalysis.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>

<!--
Code Coverage
Enable using MSBuild integration since it's easier to use in build pipelines
and likely easier to remember than the VSTest platform integration.
Also: https://github.com/coverlet-coverage/coverlet/blob/master/Documentation/KnownIssues.md#1-vstest-stops-process-execution-earlydotnet-test
-->
<PropertyGroup Condition="'$(CollectCoverage)' == 'true'">
<VSTestCollect Condition="'$(VSTestCollect)' == ''">XPlat Code Coverage</VSTestCollect>
<!-- Override this property in your projects' or solutions' Directory.Build.props to further customize code coverage. -->
<VSTestSetting Condition="'$(VSTestSetting)' == ''">$(MSBuildThisFileDirectory)CodeCoverage.runsettings</VSTestSetting>
</PropertyGroup>

<!-- TargetFramework default properties -->
<PropertyGroup>
<!-- Client libraries are moving forward to NS 2.0 and Net 4.6.1 as the min supported versions -->
Expand Down
4 changes: 2 additions & 2 deletions eng/Packages.Data.props
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<PackageReference Update="Azure.Storage.Blobs.ChangeFeed" Version="12.0.0-preview.1" />
<PackageReference Update="BenchmarkDotNet" Version="0.11.5" />
<PackageReference Update="Castle.Core" Version="4.4.0" />
<PackageReference Update="coverlet.msbuild" Version="2.9.0" />
<PackageReference Update="coverlet.collector" Version="1.3.0" />
<PackageReference Update="FluentAssertions" Version="5.10.3" />
<PackageReference Update="FsCheck.Xunit" Version="2.14.0" />
<PackageReference Update="Microsoft.Azure.Amqp" Version="2.4.8" />
Expand Down Expand Up @@ -69,7 +69,7 @@
<PackageReference Update="Microsoft.IdentityModel.Clients.ActiveDirectory" Version="4.5.1" />
<PackageReference Update="Microsoft.Identity.Client" Version="4.22.0" />
<PackageReference Update="Microsoft.Identity.Client.Extensions.Msal" Version="2.16.5" />
<PackageReference Update="Microsoft.NET.Test.Sdk" Version="16.1.0" />
<PackageReference Update="Microsoft.NET.Test.Sdk" Version="16.8.0" />
<PackageReference Update="Microsoft.NETCore.Platforms" Version="2.2.1" />
<PackageReference Update="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.0" />
<PackageReference Update="Microsoft.Rest.ClientRuntime.Azure.Authentication" Version="[2.4.0]" />
Expand Down
4 changes: 3 additions & 1 deletion eng/pipelines/templates/jobs/archetype-sdk-client.yml
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ jobs:
Windows_NetCoreApp:
OSVmImage: "windows-2019"
TestTargetFramework: netcoreapp2.1
${{ if eq(variables['System.TeamProject'], 'internal') }}:
CollectCoverage: true
Windows_NetCoreApp_ProjectReferences:
OSVmImage: "windows-2019"
TestTargetFramework: netcoreapp2.1
Expand Down Expand Up @@ -163,7 +165,7 @@ jobs:
condition: and(succeeded(), eq(variables['CollectCoverage'], 'true'))
displayName: ReportGenerator
inputs:
reports: '**/*coverage.netcoreapp2.1.cobertura.xml'
reports: 'sdk/**/coverage.cobertura.xml'
targetdir: '$(Build.SourcesDirectory)'
reporttypes: Cobertura
- task: PublishCodeCoverageResults@1
Expand Down

0 comments on commit e3ed72c

Please sign in to comment.