Analysis Scope - Sonar Test code metrics

Soncar Cloud documentation states that test code should be scoped differently

However, in the metrics documentation I can’t find the test code specific metrics alluded to in the paragraph.

What leads to these questions is the documented example where they have both sonar.exclusion and sonar.test.inclusions doesn’t show any test code metric I can find in the Sonar Cloud UI and therefore to me feels no different than just applying sonar.exclusion only.

I believe there is a nuance that I am not understanding and I hope someone can help explain. Thanks

Hi,

Welcome to the community!

We don’t calculate a lot of test-related metrics. In fact, by default, our “calculation” consists of making sure tests are excluded from the normal metrics (E.G. Lines of Code, Complexity &etc.). The test-related metrics we do have come straight from test execution reports, if you choose to feed them into analysis.

Distinguishing test files from source files is less about calculating test metrics and more about

a) excluding tests from code-related metrics, including LOC, against which licensing is charged
b) executing the right rules against the files. For instance, it makes no sense to run strict taint-analysis rules against tests, when they’re never going to take user input in production.

Does this help?

 
Ann

Hi Ann,

Thanks for the response. Based on what you described, I can get the same result by using sonar.exclusion vs sonar.test.inclusions especially if I do not want to not see my test code show up in the tree view of the Code tab.

Hi,

Apples & grapefruits.

sonar.exclusions removes files from the set described by sonar.sources.

sonar.test.inclusions narrows the set described by sonar.tests

If you don’t want your test code to show up at all, simply omit it from sonar.sources and don’t define sonar.tests.

 
HTH,
Ann