Is there an easy way to make tests not up to date if they fail?

I understand that when tests are run the next time they are considered up to date and not re-run. I am totally fine with that if the tests passed, but if the tests fail I don’t want them considered up to date.

Currently if I run a build and tests fail the build stops with the failure. But if I run the build again it doesn’t rerun the tests and continues on running the tasks that depend on test, which seems really, really broken to me.

Is there some easy way to set that up that I have missed? I have multiple projects in the build so would rather not have to do anything too hacky and have to repeat that multiple times.

One solution would be to scan the test result files and see if I find any failures in an upToDateWhen spec but that seems like a bad hack. Surely there is an easier way to accomplish this.

Tasks that fail are not considered UP-TO-DATE. This is already the default behavior. Your build would have to do something explicitly to change this.

I would swear to you that I ran the same gradle command twice in a row and the first time it failed due to tests and the second time it did not run the tests and went on and did everything after tests and it was successful, which is why I asked the question.

However today I cannot reproduce that behavior, so you are correct.