Get metrics for test projects

  • We’re using the latest SonarQube version 7.2.1 (developer edition)
  • We are trying to get metrics from pure test projects as well (via TFS)
  • Played around with variations of source.include and test.exclude.

As far as I understood test projects are explicitely excluded from the metrics. Now we would also like to verify our unit test. The unit tests run fine, during the TFS build it also shows how many files are indexed (from a pure test project).
The project scan info seems to be uploaded to the SonarQube server, but no metrics are listed at all.

Is there a way to not exclude test projects at all?

Using test.exclude or source.include had effects on the number of indexed files, but in no case the metrics appeared on the server.

hi @Georg and welcome to our community!

The latest version is 7.9 LTS. :slight_smile: It has lots of new cool features.

The short answer is that we do not support the scanning of test files. We have this on the roadmap (see MMF-1451 - as you can see, it involves quite a lot of work). You can also add a vote on Allow enabling sonar rules for test sources and maybe add a comment in the thread to represent the dotnet community :slight_smile:

Did you try modifying sonar.msbuild.testProjectPattern, to make sure it’s not treating the test projects as such ?(see Detection of Test Projects section inside the SonarScanner for MSBuild documentation). This will mean, though, that the test projects will be treated exactly like non-test source code.

Hi Andrei,

Thanks for the feedback!

I’ve tried this:

/d:sonar.inclusions=* /d:sonar.test.exclusions=* /d:sonar.msbuild.testProjectPattern=xyz

I’ve set it to xyz to detect nothing as test project. Unfortunately that didn’t help.
I’m sure to vote on that issue :wink:

1 Like

hey @Georg. You could also try to set <SonarQubeTestProject>false</SonarQubeTestProject> in the csproj file as described in this thread: Sonarscanner not analyzing netcoreapp2.2 . This should take precedence over anything else.