2013-06-04 31 views
11

我有一個如下所示的項目結構。我想在Gradle中使用TestReport功能將所有測試結果聚合到一個目錄。 然後,我可以通過一個index.html文件訪問所有子項目的所有測試結果。 我該如何做到這一點?使用TestReport彙總Gradle多項目測試結果

. 
|--ProjectA 
    |--src/test/... 
    |--build 
    |--reports 
     |--tests 
     |--index.html (testresults) 
     |--.. 
     |--.. 
|--ProjectB 
    |--src/test/... 
     |--build 
     |--reports 
      |--tests 
      |--index.html (testresults) 
      |--.. 
      |--.. 

回答

21

Example 23.13. Creating a unit test report for subprojectsGradle 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 
} 

完全工作的樣品可從全搖籃分佈samples/testing/testReport

+0

嗨皮特,我需要一些方向。就我而言,我只有一個項目,即ProjectA,在gradle clean build integrationTest之後,我看到build/jacoco/test.exec和build/jacoco/integrationTest.exec。在build/reports/tests/xxxxxx下,我看到了單元測試的index.html或者集成測試,也就是說,如果我運行gradle clean build,我會看到單元測試index.html,如果我運行gradle clean build integrationTest,那麼它會覆蓋數據在build/reports/tests/xxx中,並在同一文件夾(build/reports/tests)中獲取integrationTest任務的新數據。 –

+0

同樣,當我運行sonar-runner時,我確實看到兩個.exec文件在JacocoSensor中被拾取,我也看到jacoco整體.exec在.sonar文件夾下和build/reports/jacoco文件夾下的工作區中創建。 sonar-runner成功完成,但我沒有在Sonar項目的儀表板中看到結果,即使我已經將這兩個小部件設置爲顯示單元測試/覆蓋率和集成測試。請告知我可能錯過了什麼。 –

+0

您需要爲集成測試設置單獨的報告目錄(請參閱[Gradle Build Language Reference](http://gradle.org/docs/current/dsl/index.html))。不確定Sonar問題。 –

1

對於「connectedAndroidTest的存在是由谷歌發佈的方法。(https://developer.android.com/studio/test/command-line.html#RunTestsDevice多模塊報告部分))

  1. 添加了 'Android的報告' 插件到你項目的build.gradle。

    apply plugin: 'android-reporting'

  2. 執行額外的 'mergeAndroidReports' 的說法了Android測試。它會將項目模塊的所有測試結果合併到一個報告中。

    ./gradlew connectedAndroidTest mergeAndroidReports

+0

雖然文檔說它也可以合併單元測試,但是運行這個任務取決於我想要的咖啡測試。 – tasomaniac