浏览代码

Add code coverage with coverlet

Oren Novotny 6 年之前
父节点
当前提交
a14e4775d4

+ 1 - 0
.gitignore

@@ -117,6 +117,7 @@ stylecop.*
 artifacts/
 Generated_Code #added for RIA/Silverlight projects
 ApiApprovalTests.*.received.txt
+coverlet/
 
 # Backup & report files from converting an old project file to a newer
 # Visual Studio version. Backup files are not needed, because we have git ;-)

+ 4 - 0
Ix.NET/Source/Directory.build.props

@@ -25,6 +25,10 @@
     <PackageReference Include="Nerdbank.GitVersioning" Version="2.3.105" PrivateAssets="all" />
   </ItemGroup>
 
+  <ItemGroup Condition="'$(IsTestProject)' == 'true'">
+    <PackageReference Include="coverlet.msbuild" Version="2.5.1" />
+  </ItemGroup>
+
   <Target Name="AddCommitHashToAssemblyAttributes" BeforeTargets="GetAssemblyAttributes">
     <ItemGroup>
       <AssemblyAttribute Include="System.Reflection.AssemblyMetadataAttribute" Condition=" '$(SourceRevisionId)' != '' ">

+ 7 - 0
Ix.NET/Source/Directory.build.targets

@@ -22,5 +22,12 @@
   <PropertyGroup>
     <Product>$(AssemblyName) ($(TargetFramework))</Product>
   </PropertyGroup>
+  
+  <PropertyGroup Condition="'$(IsTestProject)' == 'true'">
+    <UseSourceLink>true</UseSourceLink>
+    <CoverletOutputFormat>cobertura</CoverletOutputFormat>
+    <Exclude>[xunit.*]*</Exclude>
+    <CoverletOutput>$(MSBuildThisFileDirectory)coverlet/raw/$(AssemblyName)/$(TargetFramework)/</CoverletOutput>
+  </PropertyGroup>
 
 </Project>

+ 1 - 1
Ix.NET/Source/System.Interactive.Tests/System.Interactive.Tests.csproj

@@ -1,7 +1,7 @@
 <Project Sdk="Microsoft.NET.Sdk">
 
   <PropertyGroup>
-    <TargetFrameworks>netcoreapp2.1;net461</TargetFrameworks>
+    <TargetFrameworks>netcoreapp2.1;net461;netcoreapp3.0</TargetFrameworks>
     <NoWarn>$(NoWarn);CS0618</NoWarn>
   </PropertyGroup>
 

+ 18 - 1
azure-pipelines.ix.yml

@@ -57,13 +57,30 @@ steps:
     verbosityPack: Minimal
   displayName: Pack
 
+- task: DotNetCoreCLI@2  
+  inputs:
+    command: custom
+    custom: tool
+    arguments: install --tool-path . dotnet-reportgenerator-globaltool
+  displayName: Install ReportGenerator tool
+
 - task: DotNetCoreCLI@2
   inputs:
     command: test
     projects: Ix.NET/Source/**/*.Tests.csproj
-    arguments: -c $(BuildConfiguration) -s $(System.DefaultWorkingDirectory)/Ix.NET/Source/CodeCoverage.runsettings /p:DebugType=Full
+    arguments: -c $(BuildConfiguration) /p:CollectCoverage=true /p:SignAssembly=false 
   displayName: Run Tests
 
+- script: reportgenerator -reports:$(Build.SourcesDirectory)/Ix.NET/Source/coverlet/raw/**/coverage.cobertura.xml -targetdir:$(Build.SourcesDirectory)/Ix.NET/Source/coverlet/reports -reporttypes:"HtmlInline_AzurePipelines;Cobertura"
+  displayName: Create reports
+
+- task: PublishCodeCoverageResults@1
+  displayName: 'Publish code coverage'
+  inputs:
+    codeCoverageTool: Cobertura
+    summaryFileLocation: '$(Build.SourcesDirectory)/Ix.NET/Source/coverlet/reports/Cobertura.xml'
+    reportDirectory: '$(Build.SourcesDirectory)/Ix.NET/Source/coverlet/reports'
+
 - task: PowerShell@2
   displayName: Authenticode Sign Packages
   inputs: