Skip to content

Commit

Permalink
Calculate and display code coverage report (#346)
Browse files Browse the repository at this point in the history
  • Loading branch information
VladislavAntonyuk authored Apr 2, 2022
1 parent c5e0b76 commit 5e3d300
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 25 deletions.
17 changes: 4 additions & 13 deletions .runsettings
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,11 @@

<DataCollectionRunSettings>
<DataCollectors>
<DataCollector friendlyName="Code Coverage" uri="datacollector://Microsoft/CodeCoverage/2.0" assemblyQualifiedName="Microsoft.VisualStudio.Coverage.DynamicCoverageDataCollector, Microsoft.VisualStudio.TraceCollector, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<DataCollector friendlyName="XPlat code coverage">
<Configuration>
<CodeCoverage>
<Functions>
<Include>
<Function>.*CommunityToolkit.Maui\..*</Function>
</Include>
<Exclude>
<Function>.*Tests.*</Function>
<Function>.*get_.*</Function>
<Function>.*set_.*</Function>
</Exclude>
</Functions>
</CodeCoverage>
<Format>cobertura</Format>
<SkipAutoProps>true</SkipAutoProps>
<IncludeTestAssembly>false</IncludeTestAssembly>
</Configuration>
</DataCollector>
</DataCollectors>
Expand Down
37 changes: 27 additions & 10 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,26 +67,34 @@ jobs:
Write-Host "##vso[build.updatebuildnumber]$fullVersionString"
displayName: Set NuGet Version to PR Version
condition: and(succeeded(), eq(variables['build.reason'], 'PullRequest'))
# build, test and pack the packages
# test
- task: DotNetCoreCLI@2
displayName: 'Run Unit Tests'
inputs:
command: test
command: 'test'
projects: '$(PathToCommunityToolkitUnitTestCsproj)'
arguments: '--configuration Release --settings ".runsettings" --collect "Code coverage"'
- task: DotNetCoreCLI@2
displayName: 'Check Dependencies'
inputs:
command: 'custom'
custom: 'list'
arguments: 'package --vulnerable --include-transitive'
projects: $(PathToSolution)
arguments: '--configuration Release --settings ".runsettings" --collect "XPlat code coverage" --logger trx --results-directory $(Agent.TempDirectory)'
publishTestResults: false
- task: PublishTestResults@2
displayName: 'Publish Test Results'
inputs:
testResultsFormat: VSTest
testResultsFiles: '**/*.trx'
searchFolder: $(Agent.TempDirectory)
- task: PublishCodeCoverageResults@1
displayName: 'Publish Code Coverage Results'
inputs:
codeCoverageTool: 'Cobertura'
summaryFileLocation: '$(Agent.TempDirectory)/**/coverage.cobertura.xml'
failIfCoverageEmpty: true
# build sample
- task: VSBuild@1
displayName: 'Build Community Toolkit Sample'
inputs:
solution: '$(PathToCommunityToolkitSampleCsproj)'
configuration: 'Release'
msbuildArgs: '/restore'
# pack
- task: VSBuild@1
displayName: 'Build and Pack CommunityToolkit.Maui.Core'
inputs:
Expand All @@ -99,6 +107,15 @@ jobs:
solution: '$(PathToCommunityToolkitCsproj)'
configuration: 'Release'
msbuildArgs: '/restore -t:pack -p:PackageVersion=$(NugetPackageVersion) -p:Version=$(NugetPackageVersion) -p:IncludeSymbols=true -p:SymbolPackageFormat=snupkg'
# check vulnerabilities
- task: DotNetCoreCLI@2
displayName: 'Check Dependencies'
inputs:
command: 'custom'
custom: 'list'
arguments: 'package --vulnerable --include-transitive'
projects: $(PathToSolution)
# publish
- task: PowerShell@2
displayName: 'Copy NuGet Packages to Staging Directory'
inputs:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,15 @@
<ItemGroup>
<PackageReference Include="FluentAssertions" Version="6.5.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
<PackageReference Include="Xunit" Version="2.4.1" />
<PackageReference Include="Xunit.Runner.VisualStudio" Version="2.4.3" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.1.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
Expand Down

0 comments on commit 5e3d300

Please sign in to comment.