Exclude complexity rule for Go test files

Go test files are next to their targets: /foo/action.go and /food/action_test.go

I want the test file to count for coverage (obviously), but I don’t want the “over-complex” or “too-many parameters” violations for the test functions themselves

How to configure that?

Cheers

Hey there.

To clarify, you generally don’t want your test files themselves to be tested (it’s a bit “turtles all the way down”), but you do want those test files to cover the source files, which should be measured to determine how much of the source code is tested.

So in SonarQube that means:

In practice, with Go projects, where test files live right next to the source files, that tends to look like this:

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