To skip the build logs when running dotnet test --list-tests, you can use the --no-build flag (if the project is already built) and suppress MSBuild output with -v:quiet or -v:m.
Option 1: Use --no-build (if already built)
If your project is already built, you can skip the build phase entirely:
sh
dotnet test --no-build --list-tests
This prevents MSBuild from logging compilation details.
Option 2: Reduce Verbosity with -v:quiet
To minimize output, set the verbosity to quiet:
sh
dotnet test --list-tests -v:quiet
This suppresses most MSBuild logs but still shows the test list.
Option 3: Pipe to findstr (Windows) or grep (Linux/macOS)
If you just want the test names and nothing else, you can filter the output:
Windows (PowerShell/Cmd)
sh
dotnet test --list-tests | findstr /i "MyNamespace"
Linux/macOS (Bash)
sh
dotnet test --list-tests | grep "MyNamespace"
This extracts only lines containing test names.
Option 4: Use --logger "console;verbosity=quiet"
You can explicitly set the logger to minimal output:
sh
dotnet test --list-tests --logger "console;verbosity=quiet"
Best Solution (Combined Approach)
For the cleanest output:
sh
dotnet test --no-build --list-tests -v:quiet
This:
Skips the build (--no-build).
Reduces MSBuild noise (-v:quiet).
Only shows the test list.
Expected Output
Instead of seeing:
code
Determining projects to restore...
All projects are up-to-date for restore.
MyProject -> bin/Debug/net8.0/MyProject.dll
MyProject.Tests -> bin/Debug/net8.0/MyProject.Tests.dll
Test run for /path/to/MyProject.Tests.dll (.NETCoreApp,Version=v8.0)
Microsoft (R) Test Execution Command Line Tool Version 17.9.0
Copyright (c) Microsoft Corporation. All rights reserved.
The following Tests are available:
MyProject.Tests.UserServiceTests.User_Should_Be_Created_Successfully
MyProject.Tests.UserServiceTests.User_Should_Not_Be_Created_With_Empty_Name
You'll just see:
code
The following Tests are available:
MyProject.Tests.UserServiceTests.User_Should_Be_Created_Successfully
MyProject.Tests.UserServiceTests.User_Should_Not_Be_Created_With_Empty_Name
Bonus: JSON Output (for scripting)
If you need structured output (e.g., for automation), use: