# Fast failing gradle builds

**URL:** https://discuss.gradle.org/t/fast-failing-gradle-builds/12076
**Category:** Help/Discuss
**Created:** [October 7, 2015, 8:03pm UTC](https://discuss.gradle.org/t/fast-failing-gradle-builds/12076 "2015-10-07T20:03:15Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![groovybayo](https://avatars.discourse-cdn.com/v4/letter/g/e9c0ed/32.png) [@groovybayo](https://discuss.gradle.org/u/groovybayo)
#### Post date: [October 7, 2015, 8:03pm UTC](https://discuss.gradle.org/t/fast-failing-gradle-builds/12076/1 "2015-10-07T20:03:16Z")

</div>

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:

> [@Stop test/build execution on first failure and flag build as failed](https://discuss.gradle.org/t/stop-test-build-execution-on-first-failure-and-flag-build-as-failed/4346):
>
> Hello, I have some long running integration tests and I would like these tests to make the build fail ‘fast’. Currently, if I have a failure, the test task still attempts to execute the remaining tests. Only after all of them executed, I get the build failure. How can I make it so when I have a failure, everything stops there and the build is flagged failed right after the first failure? I tried this one, but still can not stop gradle afterTest { desc, result -\> println "Executing t…

-and-  
[https://issues.gradle.org/browse/GRADLE-1518](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

---

<div class="post-metadata">

### Author: ![bmuschko](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/bmuschko/32/5458_2.png) [@bmuschko](https://discuss.gradle.org/u/bmuschko)
#### Post date: [October 15, 2015, 12:57pm UTC](https://discuss.gradle.org/t/fast-failing-gradle-builds/12076/2 "2015-10-15T12:57:43Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![eriwen](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/eriwen/32/4786_2.png) [@eriwen](https://discuss.gradle.org/u/eriwen)
#### Post date: [March 23, 2018, 7:32pm UTC](https://discuss.gradle.org/t/fast-failing-gradle-builds/12076/3 "2018-03-23T19:32:12Z")

</div>

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](https://docs.gradle.org/4.6/userguide/java_plugin.html#sec:test_execution)
