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

How to determine cause for erroneous coverage? (reported: 0%, actual: 100%) #521

Open
milgner opened this issue Dec 21, 2023 · 5 comments
Open
Assignees
Labels
Bug Bug issue type S: waiting for clarification Status: additional information required to proceed

Comments

@milgner
Copy link

milgner commented Dec 21, 2023

Describe the bug
I just noticed that the coverage report showed 0% coverage for some classes which there already are tests. The logs show that these tests are being executed successfully, too.

What is even more confusing is that other classes in the same sub-project and package correctly report 100% coverage.

This is a multi-project build. In the main build.gradle.kts:

dependencies {
    kover(project(":app"))
    kover(project(":api"))

    for (dir in File("${rootDir.absolutePath}/plugins").list { dir, name ->
        File("${dir.absolutePath}/$name").isDirectory && name != "build"
    }) {
        kover(project(":plugins:$dir"))
    }
}

allprojects {
  // ...
  apply(plugin = "org.jetbrains.kotlinx.kover")
  // ...
}

I suspect that this might be related to merging of coverage information from multiple projects but am not sure how. There are other projects that depend on this one and, as such, could confuse coverage tooling by having show up the class in their classpath (even though not used directly, only through their interface) without testing them.

In order to determine possible causes, we also made an experimental branch using only Jacoco and it correctly shows the coverage.

Errors
There are no errors: everything runs except that the reported data is incorrect.

Expected behavior
Test coverage should be >0% (100% for this class)

Ideally there

Reproducer
Unfortunately, open-sourcing the project will still require a couple of months before it's useful & ready 😬

Which is why the issue is titled as such: what should I do to determine the cause for the incorrect coverage myself?

Reports
image

io.redigital.spectre.spectre_host.SpectreHostRepositoryHibernateTest > can save spect:re hosts PASSED
io.redigital.spectre.spectre_host.SpectreHostRepositoryHibernateTest > maps connector information PASSED
io.redigital.spectre.spectre_host.SpectreHostRepositoryHibernateTest > can find spect:re hosts by id PASSED
io.redigital.spectre.spectre_host.SpectreHostRepositoryHibernateTest > can find spect:re hosts by hostname PASSED
io.redigital.spectre.spectre_host.SpectreHostRepositoryHibernateTest > can update spect:re hosts PASSED
io.redigital.spectre.spectre_host.SpectreHostRepositoryHibernateTest > can remove spect:re hosts PASSED

Environment

  • Kover Gradle Plugin version: 0.7.5
  • Gradle version: 8.5
  • Kotlin project type: Kotlin/JVM
  • Coverage Toolset (if customized in build script): no customization, only Kover
  • Other context important for this bug: OpenJDK 17, Multi-project build
@milgner milgner added Bug Bug issue type S: untriaged Status: issue reported but unprocessed labels Dec 21, 2023
@shanshin
Copy link
Collaborator

Hi,
could you clarify when you run the koverHtmlReport task without specifying other Gradle command,SpectreHostRepositoryHibernateTest tests are executed?

@shanshin shanshin added S: waiting for clarification Status: additional information required to proceed and removed S: untriaged Status: issue reported but unprocessed labels Dec 21, 2023
@milgner
Copy link
Author

milgner commented Dec 21, 2023

I usually only executed ./gradlew clean check which would depend on the kover tasks and generate a report. Running ./gradlew check on the top-level project where most of the sub-projects don't have any changes causes Gradle to skip test execution for some and the resulting coverage reports are missing these tests.
Thus, running ./gradlew koverHtmlReport on an already-built project doesn't execute any tests and consequently only builds new reports where everything shows up as 0% coverage.
(couldn't reproduce this behaviour just now, might have been a fluke)

I now tried running ./gradlew clean koverHtmlReport in the root project instead but the results are the same as running ./gradlew clean check.

One thing I noticed though: looking at the coverage reports inside the sub-project which contains the test, the coverage is shown as 0%, too, so the issue cannot be related to merging the various projects and sub-project structure.
In fact, I tried running ./gradlew clean :plugins:core.spectre:koverHtmlReport and, after running all the tests inside the project, it produced a report at plugins/core.spectre/build/reports/kover/html/index.html which also misses some of the tests being run.

One thing I forgot: we're using kotest and the DescribeSpec variant. Runinng on the JVM, kotest uses the JUnit platform. Not sure whether that's relevant, though: most of the tests are picked up just fine. I'll try to determine whether there are other tests missing from the reports and whether I can discern a pattern.

@shanshin
Copy link
Collaborator

shanshin commented Jan 2, 2024

Could you reproduce the problem by creating a single project to which the SpectreHostRepositoryHibernateTest test will be copied?

@shanshin
Copy link
Collaborator

@milgner, did you manage to create a producer?

@milgner
Copy link
Author

milgner commented Mar 26, 2024

@milgner, did you manage to create a producer?

Unfortunately, I did not... For the time being, we switched to Jacoco. Not sure when there might be time for a closer investigation. But we are planning to work on the build system in a little while, that could be an opportunity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Bug issue type S: waiting for clarification Status: additional information required to proceed
Projects
None yet
Development

No branches or pull requests

2 participants