Fast failing gradle builds


(Bayo Erinle) #1

Hi,
Our integration tests take a while to run and we are looking to have some sort of fail fast mechanism to save us an ample amount of time. We will like to fail the build once we encounter the first failing test.

In searching, I stumbled upon:


-and-
https://issues.gradle.org/browse/GRADLE-1518

I see on the docs you can hook on to the test listeners. Trying this is still not working for me

test {
    ...
    //fail fast hook
    afterTest { descriptor, result ->
        if (result.getResultType().equals(TestResult.ResultType.FAILURE)) {
            println "$descriptor.name: ${result.getResultType()}... fast failing build!"
            throw new RuntimeException("Fast failing build!")
        }
    }
}

Can you please help shed some light on what I am doing wrong. I see the test is in failed status, the exception is thrown, but the build still continues. I’ll like to halt it on test failures.
Also, will the same work in terms of parallel build executions? i.e. when you have set maxParallelForks to be more than 1


(Benjamin Muschko) #2

I just tried this out. Seems like it doesn’t work. I thought that it would have worked.

Would you be interested in working on a fix?


(Eric Wendelin) #3

This is now a first-class option in Gradle 4.6. See https://docs.gradle.org/4.6/userguide/java_plugin.html#sec:test_execution