2017-05-11 2 views
1

マルチモジュールプロジェクトでテストを含むgradleタスクを実行した後、すべてのモジュールのテスト失敗の概要を表示し、例えばテストを含むgradleタスクの完了後にすべてのテスト失敗のリストを表示するには

 
module 1: 

testmodule1thing1 PASSED 
testmodule1thing2 FAILED 

results 
2 tests 1 passed 1 failed 

module 2: 
testmodule2thing1 PASSED 
testmodule2thing2 FAILED 

results 
2 tests 1 passed 1 failed 

module 3: 
testmodule3thing1 FAILED 

results 
1 tests 1 passed 1 failed 

BUILD FAILED 

========= I already have everything above this line 

test failures: 
testmodule1thing1 
testmodule2thing2 
testmodule3thing1 

========= I want everything between the last line and this line 

これは可能ですか?もしそうなら、どうですか?完全なタスクの要約が不可能な場合は、モジュールごとのサマリーでライブできる。

答えて

2

testListenerをbuildFinishedフックと組み合わせて使うことができる。

allprojects { 
    // add a collection to track failedTests 
    ext.failedTests = [] 

    // add a testlistener to all tasks of type Test 
    tasks.withType(Test) { 
     afterTest { TestDescriptor descriptor, TestResult result -> 
      if(result.resultType == org.gradle.api.tasks.testing.TestResult.ResultType.FAILURE){ 
       failedTests << ["${descriptor.className}::${descriptor.name}"] 
      } 
     } 
    } 

    // print out tracked failed tests when the build has finished 
    gradle.buildFinished { 
     if(!failedTests.empty){ 
      println "Failed tests for ${project.name}:" 
      failedTests.each { failedTest -> 
       println failedTest 
      } 
      println "" 
     } 
    } 
} 

あなたの失敗したテストのためのより良い可視性を持っている別のオプションは、多分Gradleのビルドスキャン(https://plugins.gradle.org/plugin/com.gradle.build-scan)を使用している:非常に簡単な解決策は、この最初のドラフトのように見えることができます。

+0

ありがとう! – ChickenWing

関連する問題