Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question/feature request: possibility to exclude functions annotated with given annotation (e.g. Composables) from coverage calculation #121

Closed
plnice opened this issue Jan 18, 2022 · 6 comments
Labels
Feature Feature request issue type Kover Coverage Tool
Milestone

Comments

@plnice
Copy link

plnice commented Jan 18, 2022

One of the biggest struggles with code coverage in my Android project is that we have a very little code coverage reported by the JaCoCo due to the fact that the project uses Jetpack Compose. We calculate unit tests coverage, however, Composables should be tested using UI tests (https://developer.android.com/jetpack/compose/testing). We'd like to exclude @Composable-annotated Kotlin functions from unit tests coverage calculation, however, there's no way to do this with JaCoCo (jacoco/jacoco#1208, jacoco/jacoco#1259). If kover would support to exclude such code, that would be a game changer for us and definitely we would switch from JaCoCo to kover, once it's stable.

@plnice plnice changed the title Question/feature request: possibility to exclude functions annotated with given annotation (e.g. Composables) Question/feature request: possibility to exclude functions annotated with given annotation (e.g. Composables) from coverage calculation Jan 18, 2022
@shanshin shanshin added this to the Release 0.8.0 milestone Apr 8, 2022
@stantronic
Copy link

Related feature idea - provide an annotation like @KoverExclude that can be manually added to classes and functions to exclude from coverage. This would be preferable in my view to long lists of exclusions in gradle files which lack the context of what those classes are.

@qwwdfsad
Copy link
Member

I second the idea -- it would be nice to both have @Generated package-agnostic annotation to exclude autogenerated code as well as user-provided one, such as @Composable

@rbrauwers
Copy link

rbrauwers commented Jun 21, 2022

Related feature idea - provide an annotation like @KoverExclude that can be manually added to classes and functions to exclude from coverage. This would be preferable in my view to long lists of exclusions in gradle files which lack the context of what those classes are.

@stantronic suggestion is great. As one use case, it would make possible remove Compose @Preview(s) from code coverage.

@headsvk
Copy link

headsvk commented Jun 24, 2022

I tried using @Generated on previews with Jacoco and the problem was that it doesn't apply to lambdas and it got verbose tagging all lambdas. Would be nice if Kover could handle it automatically.

@ExcludedFromGeneratedReports
@Preview(backgroundColor = 0xFFFFFFFF, showBackground = true)
@Composable
private fun HomePagePreview() {
    Theme @ExcludedFromGeneratedReports {
        HomePage(
            title = "Hello World",
            onClose = @ExcludedFromGeneratedReports {},
        )
    }
}

Since jacoco/jacoco#1208 was closed as won't fix, I would gladly switch to the IntelliJ agent if it provided better support for Compose.

@samuelneff
Copy link

Huge +1000 for this. When I worked in JS world we would annotate individual lines or blocks that could not be covered and then set the code coverage requirement to 100%. It was far more powerful than an arbitrary number like 80% where we would not know what the 20% uncovered actually was.

@shanshin
Copy link
Collaborator

shanshin commented Oct 3, 2022

Implemented in 0.6.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature Feature request issue type Kover Coverage Tool
Projects
None yet
Development

No branches or pull requests

7 participants