測試報告彙總外掛(外掛 ID:test-report-aggregation
)提供用於彙總多個 Test 任務調用(可能跨越多個 Gradle 專案)結果,並將其整合到單一 HTML 報告中的任務和配置。
用法
若要使用測試報告彙總外掛,請在您的建置腳本中加入以下內容
plugins { id 'test-report-aggregation' }
plugins { id("test-report-aggregation") }
請注意,除非與 JVM 測試套件外掛 協同應用,否則此外掛不會採取任何動作。Java 外掛 會自動應用 JVM 測試套件外掛。
現在有兩種方法可以跨多個子專案收集測試結果
範例 2 也可用於透過根專案彙總結果。
測試報告彙總外掛目前不適用於 com.android.application 外掛。 |
任務
當專案也應用 jvm-test-suite
外掛時,會為每個測試套件新增以下任務
測試套件AggregateTestReport
— TestReport-
依賴於:符合以下屬性的變體的成品
透過
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 命令中指定 |
自動報告建立
當專案也應用 jvm-test-suite
外掛時,會為每個測試套件新增以下報告物件
測試套件AggregateTestReport
— AggregateTestReport-
建立彙總 Jacoco 報告,彙總所有專案相依性中具有給定 名稱 的所有測試套件。
手動報告建立
當專案未應用 jvm-test-suite
外掛時,您必須手動註冊一個或多個報告
範例 1. 建立報告容器
build.gradle.kts
reporting {
reports {
val testAggregateTestReport by creating(AggregateTestReport::class) { (1)
testSuiteName = "test"
}
}
}
build.gradle
reporting {
reports {
testAggregateTestReport(AggregateTestReport) { (1)
testSuiteName = "test"
}
}
}
1 | 建立名為 testAggregateTestReport 的 AggregateTestReport 類型報告,彙總所有專案相依性中具有給定 TestSuite#getName() 的所有測試套件。 |
報告建立會自動建立後端任務,以依給定的測試套件類型值進行彙總。