Unit Testing on SonarQube

Template for a good new topic, formatted with Markdown:

  • ALM used — (Azure DevOps)
  • CI system used – ( Azure DevOps)
  • Scanner command used when applicable (private details masked)
  • Languages of the repository – C#
  • I have setup my Sonarqube analysis on Azuredevops build pipeline, but it is throwing exception(attached). The Test cases are getting passed in Visual studio and local SonarQube setup, however they are failing in pipeline. Is there any way I can find out which test cases are failing and why?

Please suggest how should I proceed.

I have also run the sonarqube on the server, and most of the failure of the test cases is because of the reading data from Json file and it is giving me the exception as “System.NullReferenceException : Object reference not set to an instance of an object.”

Test Case:
public void MergePartialLocations(IEMPCOREDATAMODELS.Location data)
var locations = new List<IEMPCOREDATAMODELS.Location>
var mergePartialLocationsRequest = new IEMPCOREDATAMODELS.MergeLocationsRequest()
Locations = locations,
CorrelationUId = Guid.Empty,
IsProcessedRequestRequired = false,
Email = “SYSTEM”
var mergePartialLocationsResponse = new IEMPCOREDATAMODELS.MergeLocationsResponse();
mergePartialLocationsResponse = location.MergePartialLocations(mergePartialLocationsRequest, null, null, null);
var expected = 1;
Assert.Equal(mergePartialLocationsResponse.MergeResult.InsertCount, expected);

Json File Data
“LocationUId”: “00000000-4444-0000-0000-000000000001”,
“Latitude”: “19.076”,
“Longitude”: “72.8777”,
“RowStatusUId”: “00100000-0000-0000-0000-000000000000”,
“ItemState”: 0,
“CreatedByUser”: “SYSTEM”,
“CreatedByApp”: “IEMP”,
“CreatedOn”: “2020-12-18T06:07:08.538675”,
“ModifiedByUser”: “SYSTEM”,
“ModifiedByApp”: “IEMP”,
“ModifiedOn”: “2020-12-18T06:07:08.538675”,
“RowVersion”: null

However the Json file doesn’t have all the properties defined for the Location table schema/model, could it that be the reason for failure of test case?


Welcome to the community!

If this is about tests passing or failing, then it’s outside the scope of this community.


I just want to know, can sonarqube access the azure database for running the unit test cases or not?
The test cases failing is due to the Sonarqube is not able to access the Azure SQL database.


SonarQube doesn’t run your tests. So I guess the answer here is ‘no’.


We are using SonarQube in Azure pipeline. Running test cases on SonarQube locally get successfully passed, however in pipeline they are failing. Most of the test cases are reading data from Json file and throwing an exception of “System.NullReferenceException : Object reference not set to an instance of an object.”
Please suggest what should I do to get these test cases passed in pipeline also.

Yes, I mean to ask can we configure sonar scanner in such a way that it can connect to Azure database at another server, because what I have read Sonar Scanner can not connect to external server.


Analysis doesn’t connect to any database. At all. Period. It interacts with the SonarQube server via web calls and analyzes the code and already-generated reports fed into it locally. That’s all.