All things Tech with a dash of Geek for good measure!

Following on from the previous article, to add Code coverage to nopcommerce when building on Azure-Pipeline as your dev-ops pipeline, it is necessary to add the following nugets to the nopcommerce test projects:

Install Microsoft.CodeCoverage to the 4 test projects:

Microsoft.Codecoverage

Install coverlet.collector to the 4 test projects:

coverlet.collector

 

It is also necessary to adjust your build pipeline, you can do this using the following in your `azure-pipelines.yml`

pool:
name: Azure Pipelines

steps:
- task: DotNetCoreCLI@2
displayName: 'dotnet restore'
inputs:
   command: restore
   projects: ./src/NopCommerce.sln

- task: DotNetCoreCLI@2
displayName: 'dotnet build'
inputs:
   projects: ./src/NopCommerce.sln
   arguments: '--configuration $(BuildConfiguration)'

- task: DotNetCoreCLI@2
displayName: 'dotnet test'
inputs:
   command: test
   projects: |
     ./src/Tests/Nop.Core.Tests/Nop.Core.Tests.csproj
     ./src/Tests/Nop.Web.MVC.Tests/Nop.Web.MVC.Tests.csproj
     ./src/Tests/Nop.Services.Tests/Nop.Services.Tests.csproj
   arguments: '--configuration $(BuildConfiguration) --collect "XPlat Code coverage"'

- task: PublishCodeCoverageResults@1
displayName: 'Publish code coverage'
inputs:
   codeCoverageTool: Cobertura
   summaryFileLocation: '$(Agent.TempDirectory)/**/coverage.cobertura.xml'

- task: DotNetCoreCLI@2
displayName: 'dotnet publish'
inputs:
   command: publish
   arguments: '--configuration $(BuildConfiguration) --output $(Build.ArtifactStagingDirectory)'

- task: PublishBuildArtifacts@1
displayName: 'Publish Artifact'
inputs:
   ArtifactName: '$(Parameters.ArtifactName)'

This will allow full code coverage results:

codecoverageresults

If only SonarCube was also enabled ;-p but we are not the authors, so that is for another tutorial!

Leave a comment