測試報告彙總外掛(外掛 ID:test-report-aggregation)提供用於彙總多個 Test 任務調用(可能跨越多個 Gradle 專案)結果,並將其整合到單一 HTML 報告中的任務和配置。

用法

若要使用測試報告彙總外掛,請在您的建置腳本中加入以下內容

plugins {
    id 'test-report-aggregation'
}
plugins {
    id("test-report-aggregation")
}

請注意,除非與 JVM 測試套件外掛 協同應用,否則此外掛不會採取任何動作。Java 外掛 會自動應用 JVM 測試套件外掛。

現在有兩種方法可以跨多個子專案收集測試結果

  1. 從發佈版本的專案,例如應用程式或 WAR 子專案 → 發佈版本範例

  2. 使用獨立專案來指定子專案 → 獨立範例

範例 2 也可用於透過根專案彙總結果。

測試報告彙總外掛目前不適用於 com.android.application 外掛。

任務

當專案也應用 jvm-test-suite 外掛時,會為每個測試套件新增以下任務

測試套件AggregateTestReportTestReport

依賴於:符合以下屬性的變體的成品

透過 testReportAggregation 配置收集直接和可轉移專案相依性的變體。將比對以下屬性

    - org.gradle.category         = verification   (1)
    - org.gradle.testsuite.name   = test           (2)
    - org.gradle.verificationtype = test-results   (3)
1 類別屬性;值是固定的。
2 TestSuiteName 屬性;值衍生自 TestSuite#getName()
3 VerificationType 屬性;值是固定的。

有關測試執行產生的變體的更多資訊,請參閱 JVM 測試套件外掛文件的輸出變體章節。

報告

預設情況下,當任何任務失敗時(包括測試失敗),Gradle 會停止執行任務。為了確保您的建置始終產生彙總報告,請在您的 Gradle 命令中指定 --continue 選項。如需更多資訊,請參閱在發生失敗時繼續建置

自動報告建立

當專案也應用 jvm-test-suite 外掛時,會為每個測試套件新增以下報告物件

測試套件AggregateTestReportAggregateTestReport

建立彙總 Jacoco 報告,彙總所有專案相依性中具有給定 名稱 的所有測試套件。

手動報告建立

當專案未應用 jvm-test-suite 外掛時,您必須手動註冊一個或多個報告

build.gradle.kts
reporting {
    reports {
        val testAggregateTestReport by creating(AggregateTestReport::class) { (1)
            testSuiteName = "test"
        }
    }
}
build.gradle
reporting {
    reports {
        testAggregateTestReport(AggregateTestReport) { (1)
            testSuiteName = "test"
        }
    }
}
1 建立名為 testAggregateTestReportAggregateTestReport 類型報告,彙總所有專案相依性中具有給定 TestSuite#getName() 的所有測試套件。

報告建立會自動建立後端任務,以依給定的測試套件類型值進行彙總。

相依性管理

測試報告彙總外掛新增以下相依性配置

表 1. 測試報告彙總外掛 - 相依性配置
名稱 意義

testReportAggregation

用於宣告所有要彙總測試結果資料的專案相依性的配置。

aggregateTestReportResults

使用變體感知比對,從 testReportAggregation 配置取用專案相依性,以找到適當的測試套件類型。

如果專案也應用了 jvm-test-suite 外掛,則無需明確地將相依性新增至 testReportAggregation 配置。