test.ignoreFailures, but fail on buildFinished

(Róbert Papp) #1

I’m trying to achieve something like this:

allprojects {
	tasks.test.ignoreFailures true
gradle.buildFinished {
	def testTasks = gradle.taskGraph.allTasks.grep {it instanceof Test}
	if (testTasks.count { it.state.failure != null }) {
		throw new GradleException("Some tests failed")

That is: don’t fail individual :test tasks, but fail the whole build if any of those :test tasks had any failing tests. So far I’ve got nothing, gradle.taskGraph is empty (even before grep), and state.failure is null (when checked in taskGraph.afterTask), because of how org.gradle.api.tasks.testing.Test.handleTestFailures is implemented.

Any guidance would be appreciated. My ideas without know-how:

  • know how to detect if :test task failed without actual FAILED state (what I was going for above)
  • set ignoreFailures = false, but somehow recover failure and continue via afterTask
  • get test counts (success, failed, ignored) from :test task and sum them up

(Stewart Bryson) #2

Did you ever solve this?

(Róbert Papp) #3

Not really, used a hack that has a lot wrong with it, but works: