Skip to content
Latchkey

dotnet test Failed (Exit Code 1) - Read Failing Tests in CI

One or more tests failed, so dotnet test returns a non-zero exit code and fails the job. The summary line tells you how many failed; the per-test output tells you why.

What this error means

dotnet test ends with a Failed! summary and exit code 1, listing failed tests with their assertion or exception messages. The build compiled fine; the tests themselves did not pass.

dotnet test output
Failed!  - Failed:     2, Passed:   148, Skipped:     0, Total:   150
  Failed Orders.Tests.CheckoutTests.AppliesDiscount [12 ms]
  Error Message:
   Assert.Equal() Failure: Expected: 90, Actual: 100

Common causes

A genuine assertion failure or thrown exception

A test asserted a value that did not match, or the code under test threw. This is a real defect surfaced by the test, not a CI quirk.

Environment difference between local and CI

Tests that depend on time zone, culture, file paths, or environment variables can pass locally and fail on a differently-configured runner.

How to fix it

Reproduce the exact failing test

Run just the failing test with a filter and detailed logging.

Terminal
dotnet test --filter "FullyQualifiedName~CheckoutTests.AppliesDiscount" \
  --logger "console;verbosity=detailed"

Publish results to read failures clearly

Emit a TRX so CI surfaces each failing test and message.

.github/workflows/ci.yml
dotnet test --logger "trx;LogFileName=test-results.trx" \
  --results-directory ./TestResults

Remove environment dependence

  1. Pin culture/time zone in tests that are sensitive to them.
  2. Avoid hard-coded absolute paths; use temp directories.
  3. Inject configuration so tests don’t read host environment variables directly.

How to prevent it

  • Run the full test suite locally before pushing.
  • Make tests deterministic and independent of host culture/time/paths.
  • Publish TRX/JUnit results so failures are easy to triage in CI.

Related guides

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