Skip to content
Latchkey

dotnet test: Run Unit Tests in CI

dotnet test builds the test project if needed and runs its tests through VSTest, reporting pass/fail and an exit code.

test is the gate most pipelines block on. The CI-relevant flags control the build, the reporting format, and which tests run.

What it does

dotnet test restores and builds the target, then runs the test runner (xUnit, NUnit, MSTest) via VSTest. It exits non-zero if any test fails, so CI can gate on the exit code.

Common usage

Terminal
dotnet test
dotnet test -c Release --no-build
dotnet test --logger "trx;LogFileName=results.trx"
dotnet test --logger "console;verbosity=detailed"

Options

FlagWhat it does
--no-buildDo not build before running (build in a prior step)
--no-restoreSkip the implicit restore
-c, --configuration <name>Configuration to test, e.g. Release
--logger <logger>Test result logger, e.g. trx, console, junit
--filter <expr>Run only tests matching the expression
--collect "XPlat Code Coverage"Collect coverage with the coverlet collector
--results-directory <dir>Where to write result files

In CI

Run build -c Release then test -c Release --no-build so the binaries are built once. Emit a TRX or JUnit logger so the CI UI can render results and surface failures. Keep the same -c on build and test, or --no-build will fail because the expected output is missing.

Common errors in CI

"No test is available in <assembly>" means no test adapter or Microsoft.NET.Test.Sdk is referenced, or --no-build pointed at a Debug output while you built Release. "The active test run was aborted. Reason: Test host process crashed" (often with exit code 134/139) means a native crash or stack overflow in a test, not a CLI problem. NETSDK1004 ("Assets file ... not found. Run a NuGet package restore") with --no-restore means you skipped restore but never ran it.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →