Gradle - 继续选项不使用TaskExecutionListener

时间:2014-11-26 13:37:56

标签: gradle

在我的gradle文件中,我有3个Test类型的任务:

/**
 * This is a test block called 'sampleA' to run testng tests.
 */
task sampleA(type: Test) {
    include "**/Helloworld4a*"
}

/**
 * This is a test block called 'sampleB' to run testng tests.
 */
task sampleB(type: Test) {

    include "**/Helloworld4b*"
}

/**
 * This is a test block called 'sampleC' to run testng tests. 
 * This block depends on sampleB block.
 */
task sampleC(type: Test, dependsOn: sampleB) {

    include "**/Helloworld4*"
    exclude "**/Helloworld4a*"
    exclude "**/Helloworld4b*"
}

现在我创建了一个插件,我在其中添加了一个TaskExecutionListener。在TaskExecutionListener中,我只为每个任务创建一个文件,而不管任务是否成功执行。

  1. sampleA将有测试失败
  2. sampleB将有测试失败
  3. sampleC不会有失败
  4. 当我运行gradle sampleA sampleB sampleC时,它只运行sampleA,这是预期的(因为任务失败) 但是当我使用--continue选项时,结果是一样的。如果不添加监听器,我会看到sampleAsampleB都在运行。

    这是我的听众课程

    class TestInfraTaskListener implements TaskExecutionListener {
        /**
         * Generate the test results for the EMTestNGTest types
         */
        public void afterExecute(Task task, TaskState state) {
            if(task instanceof Test) {
                /* If testng test type, then generate results. */
                def resultHandler = new TestResultsHandler(task, state)
    
                /* Generate individual result files */
                resultHandler.generateResultFiles()
    
                resultHandler.uploadToJira()
                state.rethrowFailure()
            }
        }
    }
    

    当我设置ignoreFailure = true时,所有3个任务都会运行。我在这里做错了什么我只想使用sampleA选项运行sampleB--continue

    My Gradle版本为1.11(我无权升级)

1 个答案:

答案 0 :(得分:0)

好的,终于让它符合以下规则:

  1. 请勿在{{1​​}}任务
  2. 中设置ignoreFailures = true
  3. 请勿在任何情况下致电Teststate.rethrowFailure()(任务是否成功)