aggregating gradle multiproject test results using TestReport

前端 未结 5 486
深忆病人
深忆病人 2020-12-08 03:51

I have a project structure that looks like the below. I want to use the TestReport functionality in Gradle to aggregate all the test results to a single directory. Then I ca

相关标签:
5条回答
  • 2020-12-08 03:57

    For 'connectedAndroidTest's there is a approach published by google.(https://developer.android.com/studio/test/command-line.html#RunTestsDevice (Multi-module reports section))

    1. Add the 'android-reporting' Plugin to your projects build.gradle.

      apply plugin: 'android-reporting'

    2. Execute the android tests with additional 'mergeAndroidReports' argument. It will merge all test results of the project modules into one report.

      ./gradlew connectedAndroidTest mergeAndroidReports

    0 讨论(0)
  • 2020-12-08 03:58

    If using kotlin Gradle DSL

    val testReport = tasks.register<TestReport>("testReport") {
        destinationDir = file("$buildDir/reports/tests/test")
        reportOn(subprojects.map { it.tasks.findByPath("test") })
    
    subprojects {
        tasks.withType<Test> {
            useJUnitPlatform()
            finalizedBy(testReport)
            ignoreFailures = true
            testLogging {
                events("passed", "skipped", "failed")
            }
        }
    }
    

    And execute gradle testReport. Source How to generate an aggregated test report for all Gradle subprojects

    0 讨论(0)
  • 2020-12-08 04:00

    From Example 4. Creating a unit test report for subprojects in the Gradle User Guide:

    subprojects {
        apply plugin: 'java'
    
        // Disable the test report for the individual test task
        test {
            reports.html.enabled = false
        }
    }
    
    task testReport(type: TestReport) {
        destinationDir = file("$buildDir/reports/allTests")
        // Include the results from the `test` task in all subprojects
        reportOn subprojects*.test
    }
    

    Fully working sample is available from samples/testing/testReport in the full Gradle distribution.

    0 讨论(0)
  • 2020-12-08 04:08

    FYI, I've solved this problem using the following subprojects config in my root project build.gradle file. This way no extra tasks are needed.

    Note: this places each module's output in its own reports/<module_name> folder, so subproject builds don't overwrite each other's results.

    subprojects {
     // Combine all build results
      java {
        reporting.baseDir = "${rootProject.buildDir.path}/reports/${project.name}"
      }
    }
    

    For a default Gradle project, this would result in a folder structure like

    build/reports/module_a/tests/test/index.html
    build/reports/module_b/tests/test/index.html
    build/reports/module_c/tests/test/index.html
    
    0 讨论(0)
  • 2020-12-08 04:12

    In addition to the subprojects block and testReport task suggested by https://stackoverflow.com/users/84889/peter-niederwieser above, I would add another line to the build below those:

    tasks('test').finalizedBy(testReport)
    

    That way if you run gradle test (or even gradle build), the testReport task will run after the subproject tests complete. Note that you have to use tasks('test') rather than just test.finalizedBy(...) because the test task doesn't exist in the root project.

    0 讨论(0)
提交回复
热议问题