I’ve used sonarqube in the past with Java projects. I’ve recently move to a new typescript project.
The project has been setup with unit tests co-located with the files under test, and integration tests in a separate spec folder, e.g.
I’d like to include the test files for general analysis, but not for coverage which I believe is basically what the
sonar.tests settings are for.
However I can’t seem to find a way to configure this as these settings only accept folder paths, not filtering by file pattern (i.e. test files are
For now my work around is just to exclude all the test files (using
sonar.exclusions=**/*.spec.ts) but this is not ideal.
You are correct,
sonar.tests only supports a comma seperated list of directories.
We currently assume test files are in a separate folder. Could you explain why you made the choice to have test files and main source code in the same folder?
We made the decision to co-locate our source and unit test files for a couple of reasons.
- It makes it very easy to see where there are missing tests (this was before we started using proper coverage analysis tools - but is still very useful during development and code review)
- working on a reasonably large code base, it’s far easier to switch between test and source files if they’re co-located rather than having to jump between two nested folder trees
While I understand that having test files separate is more normal - I’m sure there are other developers who co-locate their test files. It would be great if sonarcloud could support glob patterns for
Is there any possibility of this feature being added to sonarcloud?
For the project structure described above, the following configuration should help: