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

Is there a way to make kover to create a coverage report based only on existing coverage data? #192

Closed
raghav-deepsource opened this issue Jun 17, 2022 · 8 comments
Labels
Question Support request issue type

Comments

@raghav-deepsource
Copy link

When I iterate on my code, I find myself making some changes, running specific tests, then checkign coverage by generating a jacoco html report with the data from the executed tests alone.

When I installed kover, I added the following to my build script:

tasks.test {
    extensions.configure(kotlinx.kover.api.KoverTaskExtension::class) {
        isDisabled = false
        binaryReportFile.set(file("$buildDir/coverage.bin"))
    }
}

If I understand correctly, this code is what makes the test task implicitly run when a task such as koverHtmlReport is run.

I would like to disable this behavior, and instead allow kover to use only what coverage it finds. If there is no coverage binary created, I expect there to be no coverage reported. If coverage was generated only for a few methods of a few classes, I expect there to be correct coverage data for those methods/classes alone, anything else can be garbage data as far as I am concerned.

This is possible in JaCoCo, as I can simply run the jacocoTestReport task independently. Is this also possible with Kover, and if so, is there some documentation on it? if not, please consider supporting this use case, as it is helpful when one does not want to waste time waiting for many time consuming tests to run when they only want to test a portion of functionality.

@raghav-deepsource raghav-deepsource changed the title Is there a way to make kover to create a coverage report based only on tests that have run separately? Is there a way to make kover to create a coverage report based only on existing coverage data? Jun 17, 2022
@shanshin
Copy link
Collaborator

shanshin commented Jun 17, 2022

Hi,

If I understand correctly, this code is what makes the test task implicitly run when a task such as koverHtmlReport is run.

not really. If you have applied the Kover plugin to the project, then all tasks with the org.gradle.api.tasks.testing.Test type of this project will be executed when running koverHtmlReport.

I would like to disable this behavior, and instead allow kover to use only what coverage it finds.

For your example you may write

tasks.test {
    extensions.configure(kotlinx.kover.api.KoverTaskExtension::class) {
        isDisabled = true
        binaryReportFile.set(file("$buildDir/coverage.bin"))
    }
}

in this case, when running koverHtmlReport, the test task will not be triggered.

it is helpful when one does not want to waste time waiting for many time consuming tests to run when they only want to test a portion of functionality

You may also disable unnecessary tests when running Gradle (if there are not very many of them).
e.g. ./gradlew koverHtmlReport -x :test

@shanshin shanshin added the Question Support request issue type label Jun 17, 2022
@raghav-deepsource
Copy link
Author

ok, so excluding the test task with the -x option will prevent automatically running tests?

@shanshin
Copy link
Collaborator

-x disables the task execution in Gradle.
The Kover ignores disabled tasks in its turn and does not expect binary report files from them.

@raghav-deepsource
Copy link
Author

raghav-deepsource commented Jun 17, 2022

Consider if I first ran the test task, which would run all tests and (i think) will also generate a coverage data file.
If I then, separately, ran ./gradlew koverHtmlReport -x test, would the coverage data for all the tests be ignored?

I am trying this out locally at the moment, and will update this thread with what happens once everything is done.

@shanshin
Copy link
Collaborator

If I then, separately, ran ./gradlew koverHtmlReport -x test, would the coverage data for all the tests be ignored?

No, coverage data for all ignored tests won't be used in the report.

@shanshin
Copy link
Collaborator

You can use the build cache to avoid re-running tests that haven't changed. In this case, the binary reports will be taken from the cache, and only the modified tests will be run.

See Gradle docs

@raghav-deepsource
Copy link
Author

Good to know, I'll try that

@raghav-deepsource
Copy link
Author

Ok, after letting tests run, and running kover while excludign the test task, it seems like coverage is actually considered, and I have a full report available.

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

No branches or pull requests

2 participants