To view your project’s code coverage in SonarQube, your Salesforce credentials need to be passed with your build.
This applies when you’re pulling your code from your Salesforce Org OR a Git repository.
In SonarQube’s general settings under CodeScan, you will find a setting called Unit Test Run Mode. To run the tests and view up to date code coverage, this needs to be set to “async” (default). To use historical test data, this can be set to “history” (if no data is available, tests will not be run). Finally, to disable running tests completely, you can set this to “disable”.
Jenkins with Git
- This assumes you have a Jenkins project set up for use with a Git repository. There is a tutorial on setting up Jenkins with CodeScan here and a guide to using Git with Jenkins here
To view you code coverage when using Jenkins as a build manager and pulling from Git, the build will need a few more string parameters and a password parameter added.
Add the string parameter
salesforce.username : Make the default value your Saleforce username eg. firstname.lastname@example.org
Add the password parameter
salesforce.password : Make the default value your Salesforce password + your Salesforce token eg. passwordtoken
These parameters will run the tests on the Force.com platform and allow the coverage results to be displayed in SonarQube.