I have an Android project that uses Kover to measure code coverage. These results are then sent to SonarQube. This all works fine except that I want some code to be excluded from code coverage.
This would be especially useful for compose previews. They usually are in the same file as the composable, and the composable should be tested, but the preview not.
With Kover I am able to exclude code like this (based on an annotation).
kover {
reports {
filters {
excludes {
annotatedBy("com.example.MyAnnotation")
}
}
}
}
When I inspect the report it ignores the class or function as expected. However when these results are sent to SonarQube, it still checks theses lines for coverage.
Probably this happens because the reports don’t contain any information on which lines should be ignored. That means I would have to set up configuration for SonarQube as well, but besides excluding whole files I couldn’t find anything on excluding individual functions.
What I tried:
- Ignore blocks of code within files (this doesn’t seem to be working for code coverage): Narrowing the focus of your analysis | SonarQube Server Documentation
- Ignore files. As a work around I could move the previews to a different file and then exclude those files. This however defeats the purpose of the previews because you can’t directly see changes when updating the composables.
How do I solve this?