loading...

Azure Devops and your tests

omnoms profile image Marko V ・2 min read

I did an example project recently for a new class library I also did (for work). Now, I wanted to publish the test results and code coverage into azure devops.

The project was made in .NET Core 3.1 and tests are run with "dotnet" command and not the vstest command in the CI/CD.

dotnet test with codecoverage as a parameter produced, apparently, a bad result file. Azure Devops was unable to parse it.... ok ?... (I reported this through twitter to the azure devops team as I did various tests and tweaks to the configurations)

So I googled a bit and found a few articles telling me to use the VSTest CI/CD step in azure devops instead. So I fiddled with that for ages trying to get it to work. Using VSTest I also had to move to a windows image for the build process which meant a few other things also had to be converted which were not available in the same format in a windows image (scripts being run). Then that ended in it not being able to build it with vstest so I had to shuffle around the steps to not make a debug/symbol build for the beta-package before it ran the tests...

A long story short... VSTest cannot run the "good" codecoverage on a .NET Core 3.1 project, and dotnet test can atleast produce a test result with code coverage but not with as high fidelity as the builtin code coverage in Visual Studio Enterprise does with a .codecoverage file.

So these are now the first steps in my azure-pipelines.yml file in case anyone ever finds this and has the same kind of issue with publishing code coverage and test results in azure pipelines for a .net core 3.1 project.

steps:
- task: NuGetAuthenticate@0
  displayName: 'NuGet Authenticate'
- script: dotnet test --logger trx --collect:"XPlat Code Coverage"
  workingDirectory: MyProjectFolder
  displayName: 'Run Tests'
- task: PublishCodeCoverageResults@1
  inputs:
    codeCoverageTool: 'cobertura'
    summaryFileLocation: $(System.DefaultWorkingDirectory)/**/TestResults/**/coverage.cobertura.xml
- task: PublishTestResults@2
  condition: succeededOrFailed()
  inputs:
    testRunner: VSTest
    testResultsFiles: '**/*.trx'

Discussion

pic
Editor guide