Sonar Cloud Code Coverage results not being generated for TSQL unit tests

  • ALM used Azure DevOps
  • Azure DevOps
    SonarCloud is not reporting on code coverage, despite running a number of unit tests against our TSQL code. In the logs for our VisualStudio test component in Azure Devops we can see that a number of unit tests have been run. However, we are also seeing the following warning in the log;
    ‘’‘2019-10-10T14:18:15.8795224Z Warning: The adapter ‘Code Coverage (Visual Studio 2010)’ will not be used for this test run. Could not load file or assembly 'Microsoft.VisualStudio.Coverage.Monitor, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’ or one of its dependencies. The system cannot find the file specified.
    2019-10-10T14:18:16.0053582Z Results File: F:\Azagent\A1_work_temp\TestResults\GBIBC-TFS17BUILD_GBIBC-ITD-22-V 2019-10-10 15_17_59.trx’’’

We have configured the unit test component to select test platform using ‘Version’ and test platform version = ‘Latest’
The order of the tasks within our build pipeline is;
Run Code Analysis
Publish quality gate result
Run unit tests

Any ideas how to make the code coverage results viewable in Sonar Cloud?

Hi @Roadkingscot

I have a few questions / remarks regarding your issue :

  • Are you using a self hosted agent or a Microsoft-hosted one ? The VSTest platform version should match the one that is installed on the machine.
  • Note that Unit tests should be run before the Run Code Analysis task on Azure in order for our Scanner / Analyzer to take the .trx files that have been written by the Unit test task.

Thank you.


In answer to your questions;
We’re using a self hosted agent.
We’ll look at moving the unit tests before the run code analysis task, but last time we did this the run code analysis task failed.

Any other suggestions?

I think that, given the log you provided, you are using a pretty old version of MSBuild or VS which is not supported by our Scanner.

We support versions 14 and above, see the doc :

1 Like

We have now swapped over the build pipeline steps so that the order is now;
Prepare analysis for SonarCloud
Build solution
Delete obj files
run code analysis

Other than this I have made no other changes. However the unit test step now fails with a 'Failed to deploy database project and none of the tests then run.

Have you any idea why, just swapping the two steps over, could possibly fail a database deployment for testing?

Your question is not clear enough, but I’ll try and guess what the issue could be. First, the tests are not running most likely because the step to deploy the database already failed.

If you don’t have a particular step to deploy the database it could be that the solution configuration is set to also deploy while building (normally I wouldn’t do recommend that). Or maybe the step to deploy the DB project is after the one that deletes de obj and there’s no output path set for the DB project and so it gets deleted with the objs.

At the end it doesn’t seem a SonarCloud issue…