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

Wrong code coverage percentage when we have Preview function in our class #736

Open
ItSNeverLate opened this issue Feb 27, 2025 · 10 comments
Assignees
Labels
Bug Bug issue type S: untriaged Status: issue reported but unprocessed

Comments

@ItSNeverLate
Copy link

Describe the bug
I can not exclue my functions which were annotated by @Preview (androidx.compose.desktop.ui.tooling.preview.Preview) in my KMP project.

@Preview
@composable
@KoverIgnore
private fun Preview() {
AppTheme {

.........

kover {
reports {
verify {
rule {
minBound(80) //80% minimum coverage
}
}
filters {
excludes {
// Entire Points
classes("MainKt") // Desktop
classes("*.MainActivity") // Android

            // Generated Classes and Resources
            classes("*.generated.*")

            // Dependency Injection
            classes("*.di.*")

            // Compose Related (UI)
             classes("*ComposableSingletons*")
            annotatedBy(
                "androidx.compose.desktop.ui.tooling.preview.Preview",
                "KoverIgnore"
            )
        }
    }
}

}

Image

Environment

  • Kover Gradle Plugin version: 0.9.1
  • Gradle version: 8.10.2
  • Kotlin project type: Multiplatform
  • Coverage Toolset: Kover
@ItSNeverLate ItSNeverLate added Bug Bug issue type S: untriaged Status: issue reported but unprocessed labels Feb 27, 2025
@ItSNeverLate ItSNeverLate changed the title Excluding function which annotated bt @Previrw Excluding function which annotated by @Previrw from code coverage Feb 27, 2025
@shanshin
Copy link
Collaborator

Hi, please provide the list of classes above Preview function

@ItSNeverLate ItSNeverLate changed the title Excluding function which annotated by @Previrw from code coverage Wrong code coverage percentage when we have Preview function in our class Feb 27, 2025
@ItSNeverLate
Copy link
Author

sorry: my problem is i have a class with two functions. and preview function is ignored and it is not listed in the class functions anymore. but the class code coverage is still 50%

Image

@ItSNeverLate
Copy link
Author

ItSNeverLate commented Feb 27, 2025

I am using this to be able to see my compose preview in android studio

@OptIn(ExperimentalMultiplatform::class)
@OptionalExpectation
@target(AnnotationTarget.FUNCTION)
expect annotation class Preview()

@ItSNeverLate
Copy link
Author

without
annotatedBy( "androidx.compose.desktop.ui.tooling.preview.Preview",
I could see preview function in the report is listed.

It means that kover ignores my function based on my configuration. But why it is counting that in class function count? (the result is 50%)

@johngray1965
Copy link

I'm see this too. I have annotatedBy("androidx.compose.desktop.ui.tooling.preview.Preview") in the config, sometimes they are correctly ignored, sometimes partially ignore, sometimes not ignored at all. In some cases, I'd have excellent coverage if it weren't for this.

@johngray1965
Copy link

Here's a good example.

Image

@ItSNeverLate
Copy link
Author

@johngray1965 exactly, it says that the class is 100% covered. But 50% of the methods. It means it considers Preview function.

@johngray1965
Copy link

There seems to be some pattern of when it's working and when its not, but I haven't been able to see it just yet.

@johngray1965
Copy link

Interesting. With my Empty example above, if I have two previews function each with a single @Preview annotation, instead of single preview function with two @Preview annotations, they are correctly ignored.

@johngray1965
Copy link

@shanshin Yeah, that's repeatable. Multiple @Preview annotations cause issues. I'm fairly sure other annotations, like @Suppress cause issues as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Bug issue type S: untriaged Status: issue reported but unprocessed
Projects
None yet
Development

No branches or pull requests

3 participants