GoLang test files are not analyzed after global exclusions pattern change

During initial configuration, I’ve mistakenly added this pattern **/*_test.go to Global Source File Exclusions list which caused a “Coverage on New Code 0.0%” problem in code analysis. After excluding this pattern from the list and rerunning the scan, it seems that Sonar is not looking for test files anyways.

This causes some problems as it seems impossible to retrospectively confirm that tests actually exist for the code. Moreover, inspecting the “Code” tab for the project, the test files are missing:


(Left: SonarQube | Right: same folder in GitLab)

I’m out of sensible ideas at this point. Is there a way to force-scan the repo or import those tests in an elegant way?

Current setup:

  • Global Source File Exclusions:
    • **/testdata/**
  • Source File Exclusions:
    • **/*_easyjson.go
    • **/*.pb.go
  • Test File Inclusions:
    • **/*_test.go

The remaining fields are empty

Community Edition - Version 10.3 (build 82913)

Hi,

You don’t need a reset; the analysis parameters are read and applied fresh at each analysis.

What you need to do is specify the locations of your test files. Yes, you’ve set an inclusion, but on its own it won’t do anything, because an inclusion say “of all the files defined, only use these”.

Try this instead:

Global Source File Exclusions:

  • **/testdata/**

sonar.sources=[comma-delimited list of source file directories]
sonar.tests=[comma-delimited list of test file directories - NO WILDCARDS]

 
HTH,
Ann

What if test files are in the same directory as the source files?

Hi,

I was afraid you might say that.

Let’s say that directory is foo. Then it’s:

sonar.sources=foo
sonar.tests=foo
sonar.tests.inclusions=**/*_test.go
sonar.exclusions=**/*_test.go, **/*_easyjson.go, **/*.pb.go

 
HTH,
Ann

By trying to remove Global exclusions, I found UI bug :slight_smile:

Basically, once you clear the list, you’re unable to save it

Hi,

That’s what that Reset button is for.

 
:smiley:
Ann