SonarCloud code coverage % for GoTest files using Bitbucket Pipeline

Hi community,

I’m looking for an help that I’m unable to get the code coverage % in Sonar Cloud for Go Test Files(main_test.go) using the below Bitbucket pipeline script.
Script to Run Go Test

  • cd src/workspace
  • go build -v -o workspace
  • go test -v -short -coverprofile workspace_coverage.out ./…
  • go tool cover -func=“workspace_coverage.out”

Below is the result of go tool command
image

Bitbucket Sonar Successfull Result

Script:

  • pipe: sonarsource/sonarcloud-scan:1.2.1
    variables:
    SONAR_TOKEN: ${SONAR_TOKEN}
    EXTRA_ARGS: ‘-X -Dsonar.sources=. -Dsonar.c.file.suffixes=- -Dsonar.cpp.file.suffixes=- -Dsonar.objc.file.suffixes=- -Dsonar.test=src/workspace/_test.go -Dsonar.test.inclusions=src/workspace/_test.go -Dsonar.go.coverage.reportPaths=src/workspace/workspace_coverage.out’

Code Coverage details in Sonar Cloud
image
Overview of Code Coverage

When i cross check with bitbucket pipeline artifact for sonar scanner it throws an warning message as below.
19:17:34.236 DEBUG: Resolving file workspace/main.go using relative path
19:17:34.237 WARN: File ‘workspace/main.go’ is not included in the project, ignoring coverage

Will be waiting for your response.

Thanks,
Sanjay A

Hi Community,

Can anyone help me out with the answer for the above problem.

Thanks,
Sanjay A

Hello @sanjay_a

I know it’s an old topic, but I was wondering if you managed to solve your problem? If yes, it would be great if you could share with us what was the problem.

If not, I invite you to have a look at this example of how someone configured his project.

And eventually at this related post:

Hope it will lead you in your researches.
If you are still stuck, feel free to come back to us with updated information.

Best,
Quentin