Go - Why test file automatically exclude from source?

Hi, I integrated sonarqube v.9.5 with golang 1.18, all was running as expected. but I got weird things. I don’t configure an sonar.exclusions but always got result exclusion unit test from source. My goal is, I want analyze unit test file to detect smell code and others rules from sonarqube. is that posisble?

result

INFO: Project configuration:
INFO:   Included sources: **
INFO:   Excluded sources: **/*_test.go
INFO:   Included tests: **/*_test.go
INFO:   Excluded sources for coverage: **/*_test.go

sonar.project.properties

sonar.projectKey=${PROJECTKEY}

sonar.sources=.
sonar.inclusions=**

sonar.tests=.
sonar.test.inclusions=**/*_test.go
sonar.coverage.exclusions=**/*_test.go

sonar.go.exclusions=**/vendor/**,**/*_mock.go
sonar.go.tests.reportPaths=go-test-report.out
sonar.go.coverage.reportPaths=go-coverage.out
sonar.go.golangci-lint.reportPaths=golangci-report.out

Hi,

Welcome to the community!

Tests get a different treatment from code in a number of ways, so if a file is identified as a test, it won’t also be treated as code. That’s why you see the mutual exclusion:

If you want all rules run against your test files, then you’ll need to drop these properties:

Although that may have other side effects.

 
HTH,
Ann

Thank for your explanation, probably I need 2 projects to scan main code and the test code its self

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.