2017-05-11 16 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

相关问题