Azure DevOps - Code Coverage - VSTest@2

  • ALM used: Azure DevOps Services
  • CI system used: Azure DevOps - Self Hosted Agent

Similar to this issue Code Coverage 0.0% Azure DevOps i cannot get Code coverage to work.

The VSTest@2 output shows that a trx file is generated. But then its added to the run attachments and very quickly i see the file is cleared up before the build then gets to the Sonarcloud analyze step.

“Adding trx file C:*_temp\TestResults*.trx to run attachments” (replaced folder name and file name with * where its identifiable account info)

It seems like the developers of VSTest suggest this is the expected behaviour VSTest should retain TestResults or give an option not to publish · Issue #10157 · microsoft/azure-pipelines-tasks · GitHub
But then how exactly is the Sonarcloud analyze step meant to pick up this information? It doesnt download it from the pipeline.

Code Coverage 0.0% Azure DevOps seems to suggest this is fixed? but im using the latest Sonarcloud extension in DevOps services.

Hi @WillEllis

Can you share your pipeline configuration as well as the logs (in debug mode) of the Run Code Analysis task please ? (you can activate the debug mode by adding the system.debug=true pipeline variable)

Thanks in advance.
Mickaël

Hi Mickaël,

I’ll look to try and get this for you. As this is a private project I do wonder if some of the log output might be sensitive, is there a better way for me to share this with you without it being on a public forum?

Thanks,
Will

Hi Mickaël,

I’ve worked out why this happened and resolved the issue.

VSTest@2 was definitely deleting the trx file but this was due to using batching of unit tests (something that needs to be set for incremental test discovery) like:
batchingBasedOnAgentsOption: 'customBatchSize' customBatchSizeValue: '1000'

This is due to the pipeline being used in 2 modes, 1 for quicker builds (using test discovery), 1 for longer builds which runs all tests and also now runs sonar.
The batching isnt needed for non-test discovery mode so I’ve removed that from the mode that runs sonar and now it can successfully pick up on the trx files.

Thanks for your help, this can be closed.

1 Like

Thanks for letting us know !

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.