Can't get SonarCloud to show Unit Tests

Hi there

I’ve spend the past few days trying to get more out of our SonarCloud. I’ve successfully set up PhpUnit coverage reports and PhpStan static analysis - but no matter what I do I can’t get PhpUnit test reports to show up in SonarCloud. It’s quite frustrating because it does not report any errors, they just don’t show up.

I’m using atlassians bitbucket pipelines as my CI/CD pipeline and as mentioned before it does not report of any errors. I have tried running the SonarCloud scan with the sonar.verbose=true which did not reveal anything new.

I can see in the logs that it imports both my coverage report as well as my php unit report (without any errors it seems).

10:14:26.442 INFO: Importing /opt/atlassian/pipelines/agent/build/phpunit-reports/junit.xml
10:14:26.558 INFO: Importing /opt/atlassian/pipelines/agent/build/phpunit-reports/coverage.xml

My configuration is as follows:

Project server settings:
  - sonar.pullrequest.provider=BitbucketCloud
Project scanner properties:
  - sonar.host.url=https://sonarcloud.io
  - sonar.organization=XXX
  - sonar.php.coverage.reportPaths=phpunit-reports/coverage.xml
  - sonar.php.phpstan.reportPaths=phpstan-report.json
  - sonar.php.tests.reportPath=phpunit-reports/junit.xml
  - sonar.projectBaseDir=/opt/atlassian/pipelines/agent/build
  - sonar.projectKey=XXX_XXX
  - sonar.scanner.app=ScannerCLI
  - sonar.scanner.appVersion=4.6.2.2472
  - sonar.sourceEncoding=UTF-8
  - sonar.sources=app
  - sonar.tests=tests
  - sonar.verbose=true
  - sonar.working.directory=/opt/atlassian/pipelines/agent/build/.scannerwork

I can confirm that going to SonarCloud -> Administration -> Background Tasks -> Task does not show any errors.

I create the PhpUnit reports like this:

php vendor/bin/phpunit --log-junit phpunit-reports/junit.xml --coverage-clover phpunit-reports/coverage.xml

I expect that going into Measures -> Coverage i would be able to see Unit Tests. But i don’t see any.

I feel like i’ve tried everything, so now i’m here hoping that a friendly soul can help me out.


Update 1:
So apparently it seems like running the exact same scan on my master branch rather than my feature branch (pull requests) works. It does actually show the Unit Test section under Measures -> Coverage.

What could be the reasoning behind this? Is SonarCloud not showing Unit Test data on PR’s?

Hi @Nicolas_Buch, welcome to the community!

Yes, you are absolutely right. This measure is not computed for pull requests.
On Pull requests, we show only the measures on New code, and this measure do not exist for new code but only for overall code.

Does it clarify?
Claire