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

Tests are not executed #391

Closed
vassilisimon opened this issue May 31, 2023 · 24 comments
Closed

Tests are not executed #391

vassilisimon opened this issue May 31, 2023 · 24 comments
Assignees
Labels
Question Support request issue type S: waiting for clarification Status: additional information required to proceed

Comments

@vassilisimon
Copy link

vassilisimon commented May 31, 2023

Hello,

When I run :app:koverXmlReport I always get:

Task :app:koverXmlReport SKIPPED
Task 'koverXmlReport' will be skipped because no tests were executed

So also sonarqube complains:

No coverage report can be found with sonar.coverage.jacoco.xmlReportPaths='/builds/os/now/abc-android//build/reports/kover/report.xml'. Using default locations: target/site/jacoco/jacoco.xml,target/site/jacoco-it/jacoco.xml,build/reports/jacoco/test/jacocoTestReport.xml

My minimal setup:

build.gradle.kts (:app)

plugins {
... 
id("org.jetbrains.kotlinx.kover")
}
dependencies {
    kover(project(":ui:mobile:xy"))
}

koverReport {
    // filters for all report types of all build variants
    filters {
        excludes {
            classes(
                "*Fragment",
                "*Fragment\$*",
                "*Activity",
                "*Activity\$*",
                "*.databinding.*",
                "*.BuildConfig"
            )
        }
    }
    defaults {
        xml {
            setReportFile(layout.buildDirectory.file("reports/kover/report.xml"))
        }
    }
}

build.gradle.kts (root)

plugins {
id("org.jetbrains.kotlinx.kover") version 0.7.0
}

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

sonarqube {
    properties {
        property("sonar.coverage.jacoco.xmlReportPaths", "$buildDir/reports/kover/report.xml")
    }
}

tasks.findByName("sonarqube")?.dependsOn("koverXmlReport")

Do you have an idea how to trigger the tests?

@vassilisimon vassilisimon added Question Support request issue type S: untriaged Status: issue reported but unprocessed labels May 31, 2023
@realdadfish
Copy link

Is this an Android project by any chance (determining from the dependency "ui:mobile:xy")? If so, you need to use

koverReport {
     androidReports("<yourBuildVariantHere>") {
         // report configuration
     }
}

This triggers the tests for me. The task that you need to execute then is named koverXmlReport<YourBuildVariant>.

@vassilisimon
Copy link
Author

vassilisimon commented May 31, 2023

Is this an Android project by any chance (determining from the dependency "ui:mobile:xy")? If so, you need to use

koverReport {
     androidReports("<yourBuildVariantHere>") {
         // report configuration
     }
}

This triggers the tests for me. The task that you need to execute then is named koverXmlReport<YourBuildVariant>.

It's an android project, yes.
Thanks for your help, I added this in the defaults block:
mergeWith("debug")
but now I get this problem:
#388

How can I apply the kover plugin after AGP? It's currently applied in the subprojects block.

And if I use the androidReports block instead of mergeWith() then I can't find the koverXmlReportDebug gradle task.

@realdadfish
Copy link

I think there is a workaround mentioned in #362

@vassilisimon
Copy link
Author

vassilisimon commented May 31, 2023

Still not clear to me where/what to execute in project.afterEvaluate { ... }.
I tried
subprojects { project.afterEvaluate { apply(plugin = "org.jetbrains.kotlinx.kover") } },

but I still get:
Android build variant 'debug' was not found - it is impossible to add it to the default report
because of mergeWith("debug") which is in the koverReport block.

@shanshin
Copy link
Collaborator

Hi,
@vassilisimon , is using tasks.findByName("sonarqube")?.dependsOn("koverXmlReportDebug") and either calling :app:koverXmlReportDebug applicable to you?

@shanshin shanshin added S: waiting for clarification Status: additional information required to proceed and removed S: untriaged Status: issue reported but unprocessed labels May 31, 2023
@shanshin
Copy link
Collaborator

afterEvaluate { It may not solve similar problems, because it will be executed in the same order in which the plugins were applied.

@vassilisimon
Copy link
Author

vassilisimon commented May 31, 2023

Hi,
@vassilisimon , is using tasks.findByName("sonarqube")?.dependsOn("koverXmlReportDebug") and either calling :app:koverXmlReportDebug applicable to you?

I tried it also, but it didn't work, as it can't find a gradle task called "koverXmlReportDebug".

@shanshin
Copy link
Collaborator

shanshin commented May 31, 2023

How can I apply the kover plugin after AGP? It's currently applied in the subprojects block.

At the moment, the most effective workflow is to apply the plugin explicitly in each project, instead of subprojects.

So you can explicitly specify the order of applying of plugins, e.g.

plugins {
    id ("com.android.application")
    id ("org.jetbrains.kotlin.android")
    id ("org.jetbrains.kotlinx.kover")
}

@vassilisimon
Copy link
Author

vassilisimon commented May 31, 2023

How can I apply the kover plugin after AGP? It's currently applied in the subprojects block.

At the moment, the most effective workflow is to apply the plugin explicitly in each project, instead of subprojects.

So you can explicitly specify the order of applying of plugins, e.g.

plugins {
    id ("com.android.application")
    id ("org.jetbrains.kotlin.android")
    id ("org.jetbrains.kotlinx.kover")
}

Okay, it's just a bit of tedious work, we have >200 modules.

And that would be the next question, do we have also to add this line for each module?

kover(project(":ui:mobile:module_1")
kover(project(":ui:mobile:module_n")
kover(project(":ui:tv:module_1")
kover(project(":ui:tv:module_n")

Right?
And is there a better solution?

@shanshin
Copy link
Collaborator

Okay, it's just a bit of tedious work, we have >200 modules.

Perhaps in this case it is better to wait for fix #362.

And that would be the next question, do we have also to add this line for each module?

The dependency must be specified only in project, in which the merged report will be generated

At the same time, you can use subprojects to add dependencies, because this does not add any actions to the afterEvaluate, unlike applying a plugin.

@vassilisimon
Copy link
Author

vassilisimon commented Jun 1, 2023

Thanks, then I'll wait for the fix of #362.

@shanshin
Copy link
Collaborator

@vassilisimon, could you please check version 0.7.2?

@vassilisimon
Copy link
Author

vassilisimon commented Jun 29, 2023

Updated setup:

build.gradle.kts (:app)

plugins {
... 
    id("org.jetbrains.kotlinx.kover")
}
dependencies {
    kover(project(":ui:mobile:xy"))
    kover(project(":x:y:z"))
    ... 200 more
}

koverReport {
    androidReports("betaPreProdRelease") {
        // filters for all report types for betaPreProdRelease builds
        filters {
            excludes {
                classes(
                    "*Fragment",
                    "*Fragment\$*",
                    "*Activity",
                    "*Activity\$*",
                    "*.databinding.*",
                    "*.BuildConfig"
                )
            }
        }
    }
}

build.gradle.kts (root)

plugins {
    id("org.jetbrains.kotlinx.kover") version 0.7.2
}

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

sonarqube {
    properties {
        property("sonar.coverage.jacoco.xmlReportPaths", "$rootDir/app/build/reports/kover/report.xml")
    }
}

tasks.findByName("sonar")?.dependsOn(":app:koverXmlReport")

With 0.7.2 it creates now a report in app/build/reports/kover/report.xml

But I've still 2 problems:

  • Kover doesn't execute all unit tests we have, only ~500 out of ~3200).
  • Sonarqube can't find any data regarding coverage.

** Edit:

If I use :app:koverXmlReportBetaPreProdDebug, then it runs all tests, but now I get:

* What went wrong:
Execution failed for task ':app:koverXmlReportBetaPreProdDebug'.
> Cannot access input property 'externalSources$kover_gradle_plugin' of task ':app:koverXmlReportBetaPreProdDebug'. Accessing unreadable inputs or outputs is not supported. Declare the task as untracked by using Task.doNotTrackState(). See https://docs.gradle.org/8.1.1/userguide/incremental_build.html#disable-state-tracking for more details.
   > Failed to create MD5 hash for file '/usr/bin/sudo' as it does not exist.

@shanshin
Copy link
Collaborator

shanshin commented Jun 30, 2023

Kover doesn't execute all unit tests we have, only ~500 out of ~3200).

It looks like this is because the tests were run only for JVM targets.
In order to run tests for any build variant when executing koverXmlReport, it is worth adding mergeWith("...")

Failed to create MD5 hash for file '/usr/bin/sudo' as it does not exist.

Have you added kover(project("...")) dependencies for the:app project?

@vassilisimon
Copy link
Author

vassilisimon commented Jul 4, 2023

Have you added kover(project("...")) dependencies for the:app project?

Yes, for all modules (build.gradle.kts (:app)):

dependencies {
    kover(project(":ui:mobile:xy"))
    kover(project(":x:y:z"))
    ... 200 more
}

It looks like this is because the tests were run only for JVM targets. In order to run tests for any build variant when executing koverXmlReport, it is worth adding mergeWith("...")

I tried it:

koverReport {
    defaults {
        mergeWith("betaPreProdDebug")
    }
}

but same issue:

* What went wrong:
Execution failed for task ':app:koverXmlReport'.
> Cannot access input property 'localSources$kover_gradle_plugin' of task ':app:koverXmlReport'. Accessing unreadable inputs or outputs is not supported. Declare the task as untracked by using Task.doNotTrackState(). See https://docs.gradle.org/8.1.1/userguide/incremental_build.html#disable-state-tracking for more details.
   > Failed to create MD5 hash for file '/usr/bin/sudo' as it does not exist.

@shanshin
Copy link
Collaborator

shanshin commented Jul 4, 2023

* What went wrong:
Execution failed for task ':app:koverXmlReport'.
> Cannot access input property 'localSources$kover_gradle_plugin' of task ':app:koverXmlReport'. Accessing unreadable inputs or outputs is not supported. Declare the task as untracked by using Task.doNotTrackState(). See https://docs.gradle.org/8.1.1/userguide/incremental_build.html#disable-state-tracking for more details.
   > Failed to create MD5 hash for file '/usr/bin/sudo' as it does not exist.

Could you show the contents of the app/build/kover/default.artifact file for this case?
I wonder if there is a mention of /usr/bin/sudo there

@vassilisimon
Copy link
Author

The content is too large, but there is no mention of /usr/bin/sudo.

We have for now a workaround for this problem:

subprojects {
    project.tasks.whenTaskAdded {
        if (this.name.toLowerCaseAsciiOnly().contains("koverxmlreport")) {
            this.doNotTrackState("Dont support state tracking")
        }
...
}

tasks.findByName(Tasks.KOVER_XML_REPORT)?.doNotTrackState("sudo issues")

@shanshin
Copy link
Collaborator

@vassilisimon

this.doNotTrackState("Dont support state tracking")

With this setting, the tests run successfully and a correct report is generated?

@vassilisimon
Copy link
Author

@shanshin Exactly.

@shanshin
Copy link
Collaborator

shanshin commented Jul 13, 2023

In this case, I think the current issue should be closed.

if the specified workaround will cause any inconvenience, then it is worth create a separate issue for this.
But since this is a very rare problem, in this case we need more information about the environment to understand the reasons why Gradle processes the /usr/bin/sudo file.

@vassilisimon
Copy link
Author

vassilisimon commented Jul 13, 2023

As it's a closed source project I can't provide more information here. At most in a private video/screen share session.

But thanks for your time & help!

@raamcosta
Copy link

raamcosta commented Jul 18, 2023

I also got this error

Execution failed for task ':app:koverXmlReportMockDebug'.
Cannot access input property 'externalSources$kover_gradle_plugin' of task ':app:koverXmlReportMockDebug'. Accessing unreadable inputs or outputs is not supported. Declare the task as untracked by using Task.doNotTrackState(). See https://docs.gradle.org/8.1/userguide/incremental_build.html#disable-state-tracking for more details.
Failed to create MD5 hash for file '/usr/bin/sudo' as it does not exist.

Besides, If I apply a workaround for task koverHtmlReport the task never finishes.

I also got this weird behavior the first couple of times, that Android Studio was asking for all kinds of permissions to access stuff on my mac.

EDIT: Some more info.

  • If I run koverPrintCoverageMockDebug (with the above workaround for disabling state tracking) I get an output, but before, I see this:

Task :app:koverLogMockDebug
[2023.07.18 17:16:49] (Coverage): Failed to check raw report file: java.io.FileNotFoundException: . (Is a directory)
[2023.07.18 17:16:49] (Coverage): Failed to load coverage data from file: /Users/rafael.costa/.gradle/daemon/8.1/.: java.io.FileNotFoundException: . (Is a directory)

  • If I run koverXmlReportMockDebug, I also get an xml, so for me, the stated workaround seems to mostly work except for html report which seem to never finish. Of course I don't know if there is still an issue that impacts accuracy that we're just masking with this state track disabling 🤔

@raamcosta
Copy link

raamcosta commented Jul 19, 2023

What I got today:

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ':app:koverVerify'.
    Cannot access input property 'localSources$kover_gradle_plugin' of task ':app:koverVerify'. Accessing unreadable inputs or outputs is not supported. Declare the task as untracked by using Task.doNotTrackState(). See https://docs.gradle.org/8.1/userguide/incremental_build.html#disable-state-tracking for more details.
    java.nio.file.FileSystemException: /System/Volumes/Data/home: Operation not permitted

Notice I am running koverVerify without any specification of a build variant, so it is trying to run on all modules even on non-android ones.
It seems like when I add the previously mentioned workaround it doesn't disable state tracking for non-android modules 🤔

I'm sorry I will add here as I go, I hope it can be somehow a bit helpful 🙏

EDIT:

Ok, so I edited the workaround described by @vassilisimon to this:

allprojects {
    apply(plugin = rootProject.libs.plugins.kover.get().pluginId)

    project.tasks.forEach {
        if (it.name.contains("kover", ignoreCase = true)) {
            println("calling doNotTrackState: MODULE ${project.name} TASK ${it.name}")
            it.doNotTrackState("Dont support state tracking")
        }
    }
}

And now it does disable track state on all kover's tasks. But now I have another error:

EXPAND ERROR
FAILURE: Build failed with an exception.

* What went wrong:
Some problems were found with the configuration of task ':app:koverLog' (type 'KoverFormatCoverageTask').
  - Gradle detected a problem with the following location: '/'.
    
    Reason: Task ':app:koverLog' uses this output of task ':compileJava' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed.
    
    Possible solutions:
      1. Declare task ':compileJava' as an input of ':app:koverLog'.
      2. Declare an explicit dependency on ':compileJava' from ':app:koverLog' using Task#dependsOn.
      3. Declare an explicit dependency on ':compileJava' from ':app:koverLog' using Task#mustRunAfter.
    
    Please refer to https://docs.gradle.org/8.1/userguide/validation_problems.html#implicit_dependency for more details about this problem.
  - Gradle detected a problem with the following location: '/'.
    
    Reason: Task ':app:koverLog' uses this output of task ':compileTestJava' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed.
    
    Possible solutions:
      1. Declare task ':compileTestJava' as an input of ':app:koverLog'.
      2. Declare an explicit dependency on ':compileTestJava' from ':app:koverLog' using Task#dependsOn.
      3. Declare an explicit dependency on ':compileTestJava' from ':app:koverLog' using Task#mustRunAfter.
    
    Please refer to https://docs.gradle.org/8.1/userguide/validation_problems.html#implicit_dependency for more details about this problem.
  - Gradle detected a problem with the following location: '/'.
    
    Reason: Task ':app:koverLog' uses this output of task ':compileKotlin' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed.
    
    Possible solutions:
      1. Declare task ':compileKotlin' as an input of ':app:koverLog'.
      2. Declare an explicit dependency on ':compileKotlin' from ':app:koverLog' using Task#dependsOn.
      3. Declare an explicit dependency on ':compileKotlin' from ':app:koverLog' using Task#mustRunAfter.
    
    Please refer to https://docs.gradle.org/8.1/userguide/validation_problems.html#implicit_dependency for more details about this problem.
  - Gradle detected a problem with the following location: '/'.
    
    Reason: Task ':app:koverLog' uses this output of task ':compileTestKotlin' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed.
    
    Possible solutions:
      1. Declare task ':compileTestKotlin' as an input of ':app:koverLog'.
      2. Declare an explicit dependency on ':compileTestKotlin' from ':app:koverLog' using Task#dependsOn.
      3. Declare an explicit dependency on ':compileTestKotlin' from ':app:koverLog' using Task#mustRunAfter.
    
    Please refer to https://docs.gradle.org/8.1/userguide/validation_problems.html#implicit_dependency for more details about this problem.
  - Gradle detected a problem with the following location: '/'.
    
    Reason: Task ':app:koverLog' uses this output of task ':test' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed.
    
    Possible solutions:
      1. Declare task ':test' as an input of ':app:koverLog'.
      2. Declare an explicit dependency on ':test' from ':app:koverLog' using Task#dependsOn.
      3. Declare an explicit dependency on ':test' from ':app:koverLog' using Task#mustRunAfter.
    
    Please refer to https://docs.gradle.org/8.1/userguide/validation_problems.html#implicit_dependency for more details about this problem.

It looks a bit more informative 🤞
Notice I get these errors when it tries to do something with "app" module which is the main one that depends on all others. I do have the dependencies block where I define kover dependencies on other modules.

@raamcosta
Copy link

raamcosta commented Jul 21, 2023

New update:

I did what the above error said to do and I managed to do everything except html report which fails with this error:

[2023.07.21 14:00:26] (Coverage): Failed to check raw report file: java.io.FileNotFoundException: /home/runner/.gradle/daemon/8.1 (Is a directory)
> Task :app:koverHtmlReport
Kover: HTML report for ':app' file:///home/runner/work/my-projectn/my-project/app/build/reports/kover/html/index.html
[2023.07.21 14:00:28] (Coverage): Failed to load coverage data from file: /home/runner/.gradle/daemon/8.1: java.io.FileNotFoundException: /home/runner/.gradle/daemon/8.1 (Is a directory)

In case it helps anyone else, here's what I ended with:

allprojects {
    apply(plugin = rootProject.libs.plugins.kover.get().pluginId)

    project.tasks.whenTaskAdded {
        if (this.name.startsWith("kover", ignoreCase = true)) {
            this.doNotTrackState("Dont support state tracking")
        }
    }

    project.tasks.forEach {
        if (it.name.startsWith("kover", ignoreCase = true)) {
            it.doNotTrackState("Dont support state tracking")
        }

        if (project.name == "app" && it.name == "koverLog") {
            it.mustRunAfter(rootProject.tasks.getByName("compileJava"))
            it.mustRunAfter(rootProject.tasks.getByName("compileTestJava"))
            it.mustRunAfter(rootProject.tasks.getByName("test"))
            it.mustRunAfter(rootProject.tasks.getByName("koverLog"))
            it.mustRunAfter(rootProject.tasks.getByName("koverGenerateArtifact"))
        }
    }
}

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

No branches or pull requests

4 participants