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.
Failed! - Failed: 2, Passed: 148, Skipped: 0, Total: 150
Failed Orders.Tests.CheckoutTests.AppliesDiscount [12 ms]
Error Message:
Assert.Equal() Failure: Expected: 90, Actual: 100Common 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.
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.
dotnet test --logger "trx;LogFileName=test-results.trx" \
--results-directory ./TestResultsRemove environment dependence
- Pin culture/time zone in tests that are sensitive to them.
- Avoid hard-coded absolute paths; use temp directories.
- 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.