Skip to content
Latchkey

Maven "There are test failures" (Surefire) - Fix in CI

The Surefire (unit) or Failsafe (integration) plugin ran your tests and at least one failed, so Maven failed the build. This is the plugin working as intended - a failing test is a build failure.

What this error means

After the test phase, Maven prints There are test failures with a count and a path to the reports directory, then BUILD FAILURE. The compile succeeded; the failure is in test execution.

mvn output
[ERROR] Tests run: 42, Failures: 1, Errors: 0, Skipped: 0
[ERROR] OrderServiceTest.shouldApplyDiscount:73 expected:<90> but was:<100>
[INFO] BUILD FAILURE
[ERROR] There are test failures.
See /workspace/target/surefire-reports for the individual test results.

Common causes

A genuine assertion failure

A test asserted something the code no longer satisfies. This is a real regression or an out-of-date test, not an infra problem.

Environment-dependent or flaky test

A test that depends on timezone, locale, ordering, or external state can pass locally and fail in CI. The fix is to make the test deterministic, not to retry blindly.

How to fix it

Read the report and reproduce locally

The surefire-reports directory has the full stack trace. Reproduce the exact failing test.

Terminal
mvn -B test -Dtest=OrderServiceTest#shouldApplyDiscount
# full report XML/txt is under target/surefire-reports/

Fix the test or the code - do not blanket-skip

Skipping tests hides the regression. Only -DskipTests temporarily and deliberately, never as a permanent fix.

Terminal
# emergency only - re-enable immediately after:
mvn -B verify -DskipTests

How to prevent it

  • Make tests deterministic - pin clock, timezone, locale, and avoid order dependence.
  • Run the full test suite in CI on every PR so regressions surface before merge.
  • Quarantine known-flaky tests explicitly rather than disabling whole modules.

Frequently asked questions

Why does the build fail when the code compiled fine?
Surefire runs after compile. A clean compile only means the code is syntactically valid; the test phase 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 →