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.
> 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.htmlCommon 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.
./gradlew :app:test --tests "com.example.OrderServiceTest.shouldApplyDiscount"
# full results: build/reports/tests/test/index.htmlFix the test or code - do not blanket-skip
Disabling tests hides the regression. Use a filter to isolate, then fix the cause.
# isolate while debugging (do not commit as the fix):
./gradlew :app:test --tests "com.example.OrderServiceTest" --infoHow to prevent it
- Make tests deterministic - pin clock, timezone, locale, avoid order dependence.
- Upload
build/reports/testsas 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?
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.