Skip to content
Latchkey

Gradle "Execution failed for task ':test'" (Failing Tests) in CI

Gradle ran the test task and at least one test failed, so it failed the build. Unlike the generic task-failure wrapper, this one is specifically about test results - the report path it prints has the failing assertions.

What this error means

The build stops with > Task :test FAILED and Execution failed for task ':test'. There were failing tests. See the report at: file://.../build/reports/tests/test/index.html.

gradle output
> Task :app:test FAILED

FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:test'.
> There were failing tests. See the report at:
  file:///workspace/app/build/reports/tests/test/index.html

Common causes

A genuine assertion failure

A test asserted something the code no longer satisfies - a real regression or an out-of-date test. The HTML report names the exact test and assertion.

Environment-dependent or flaky test

A test that depends on timezone, locale, ordering, or external state can pass locally and fail in CI. Make it deterministic rather than retrying blindly.

How to fix it

Open the report and reproduce the single test

The report directory has the stack traces. Re-run just the failing test.

Terminal
./gradlew :app:test --tests "com.example.OrderServiceTest.shouldApplyDiscount"
# full results: build/reports/tests/test/index.html

Fix the test or code - do not blanket-skip

Disabling tests hides the regression. Use a filter to isolate, then fix the cause.

Terminal
# isolate while debugging (do not commit as the fix):
./gradlew :app:test --tests "com.example.OrderServiceTest" --info

How to prevent it

  • Make tests deterministic - pin clock, timezone, locale, avoid order dependence.
  • Upload build/reports/tests as a CI artifact for post-mortem.
  • Run the full suite on every PR so regressions surface before merge.

Frequently asked questions

Why does the build fail when compilation succeeded?
The test task runs after compile. A clean compile only means the code is valid Java; the test task then asserts behavior, and a failed assertion fails the build by design.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →