Repository navigation
Description
Background
AI coding agents (Claude Code, Copilot, Cursor, Codex and others) run dotnet test and read the console output. Every line costs tokens. They work best when they can choose a short output when that is enough, and full detail when they need it.
Microsoft.Testing.Platform (MTP) already has this. NUnit tests that run under MTP get it through VSTestBridge. But most projects don't use MTP yet. A GitHub code search (approximate counts, October 2026) found about 2,700 global.json files that set "runner": "Microsoft.Testing.Platform". In comparison, about 750,000 .csproj files reference NUnit, xUnit or MSTest. Most NUnit users run in VSTest mode, where only the adapter's own settings apply.
This issue proposes adapter settings that match the MTP options, including MTP's detection of AI agents. Where an existing setting can be adjusted, adjust it. Where the old settings don't fit, new settings are fine. Some of the settings have collected 13 years of history, so this is a chance to clean up.
What MTP has
From the MTP terminal output docs:
| MTP option | Values | Effect |
|---|---|---|
--output |
Minimal, Normal (default), Detailed |
Minimal = failed results only |
--show-test-results |
passed, failed, skipped, all, none |
Which result blocks to show, combinable |
--show-stdout/--show-stderr |
All (default), Failed, None |
When to show captured test output |
--progress, --ansi |
auto, on, off |
Progress bar and escape codes |
AI agent detection: MTP 2.3.0 and later detect when they run inside an AI agent (LLMEnvironmentDetector.cs). The detection checks environment variables that the tools set, for example CLAUDECODE, CURSOR_AGENT, GEMINI_CLI, COPILOT_CLI, AI_AGENT, CODEX_CLI and a proposed generic AGENT_CLI. When it finds one, MTP:
- turns off ANSI output,
- does not show the startup banner,
- changes the default of
--show-stdout/--show-stderrfromAlltoFailed.
An explicit option always wins over the agent default.
What the adapter has today
| Setting | Default | Notes |
|---|---|---|
Verbosity |
0 |
At 0, TestLog.Info sends "NUnit Adapter x.y: Test execution started", "Running all tests in ..." and similar lines. -1 turns them off. |
ConsoleOut |
1 |
0 = none, 1 = informational message, 2 = warning. Applies to every test, passed or failed. Live output (TestOutput events) is sent as soon as it arrives. |
UseTestNameInConsoleOutput |
false |
Prefixes console output with the test name. |
IncludeStackTrace |
true |
On or off only. |
IncludeStackTraceForSuites |
true |
Same, for failures in a parent (fixture setup or teardown). |
In addition, the ReasonMessage of every test, not only skipped ones, is sent as an informational message when ConsoleOut >= 1.
In VSTest mode, the adapter doesn't draw the console. The VSTest console logger does, and it decides which result blocks to show (--logger "console;verbosity=..."). So --output and --show-test-results have no direct adapter equivalent. What the adapter controls is the messages it sends and what it attaches to each test result. That is where the noise comes from.
Proposal
-
One
AgentModesetting with levels. Each level is a preset for the individual settings below. An individual setting that is set explicitly always wins, the same rule as in MTP.AgentModeFor the question Console Result file (see comment below) Off(no agent) Today's behavior None Auto(default)(detect) Agent detected: same as Failures. Otherwise: same asOff.As the level it picks Summary"Did it pass?" Counts and failed test names, plus the file path Failures only Failures"What broke?" Counts, failed tests with message and stack trace, output of failed tests, plus the file path Failures only Full"Why flaky or slow?" Same as FailuresFull run, including passed tests All levels except
Off: no banner or informational lines,ShowStdout/ShowStderr = Failed,ReasonMessageonly for skipped and failed tests, and one line with the result file path.Detection for
Autouses the same environment variables as MTP. Keep the list in one place so it is easy to update when MTP adds tools. Detection only picks the default level; it never overrides a level that is set.Failuresis the detected default because an agent that runs tests usually wants to know what broke.With
Autoas the default, a human runningdotnet testin an AI tool's terminal also gets the shorter output. MTP does the same.AgentMode=Offrestores today's output. -
Replace
ConsoleOutwithShowStdout/ShowStderr=All | Failed | None, the same names and values as MTP.Failedneeds the output buffered per test until the result is known. The listener already collectsOutputNodesper test ID.- Keep
ConsoleOutas a deprecated alias:0=None,1and2=All. Consider whether the warning level (2) is still needed. - In agent mode, the default is
Failed, as in MTP.
-
Suppress the banner and informational lines in agent mode. That is the same as
Verbosity = -1, but only as a default. An explicitVerbositywins. -
Send
ReasonMessageonly for skipped, ignored and inconclusive tests, and for failed tests whenShowStdout = Failed. It should not be sent for passed tests inFailedmode. -
Stack traces: the framework's
StackFilteralready removes NUnit's own frames. Check whether the remaining frames (async state machine andSystem.Runtimeframes) are still noise for agents. If they are, addStackTrace = Full | Filtered | Noneto replace the two booleans. -
Document the agent setup in the adapter docs: the settings above, the VSTest
--logger "console;verbosity=minimal"option, and the command-line form that works without a runsettings file:dotnet test -- NUnit.AgentMode=Summary dotnet test -- NUnit.ShowStdout=Failed NUnit.Verbosity=-1
Out of scope
- JSON result output. That is a separate discussion (the serializer belongs in the framework first).
- Changes to the VSTest console logger. It belongs to Microsoft.
Related
- Console output handling reimagined #1167 "Console output handling reimagined", which covers stdout and stderr from the system under test.
ShowStdout/ShowStderrshould fit with that design.
Activity
OsirisTerje commentedon Oct 23, 2026
Addition: a result file for agents, with a pointer to it on the console
The console is hard to control fully. In VSTest mode the VSTest console logger draws it. In MTP mode, MTP's terminal reporter draws it. The two look different. The adapter only controls the messages it sends. A result file that the adapter writes doesn't have these problems.
jq)Proposal: both, each with its own job.
TestOutputXml/OutputXmlFolderMode.NUnit results: <path>. Without that line, agents rarely find the file. This is the most important part of the design.Points the design must handle:
OsirisTerje commentedon Nov 23, 2026
Two changes to the proposal, made while implementing it.
Point 4. In agent mode (
ShowStdout = Failed),ReasonMessageis now sent only for failed tests, not for skipped, ignored or inconclusive tests.Skipped and inconclusive tests are still counted in the summary line. For an agent, the count is the signal:
[Ignore]and[Explicit]reasons are the same on every run, and when a runtime skip matters, the agent can look up that one test. Reasons of failed tests are kept, because withMapWarningTo=Failedthe warning text is only in the reason.With
ShowStdout = All(the default outside agent mode) every reason is sent, as before.The table in point 1.
AgentModeis only a preset, and the individual settings are independent of it.Summarynow presetsShowStdout/ShowStderr = None, notFailed, so it stays at counts and failed test names.Summarywith an explicitShowStdout=Failedadds the output and reason of failed tests.🤖 Made by @OsirisTerje with Claude
OsirisTerje commentedon Nov 23, 2026
Narrowing after measuring. This replaces the
Summarypart of my previous comment.Under VSTest, the console logger prints a block for each failed test from the test result (message, stack trace, stdout, stderr), at every verbosity. Messages the adapter sends itself at Informational level are hidden at the default verbosity (minimal). So several parts of the proposal did nothing useful:
Failed! - Failed: 2, Passed: 21, Skipped: 3.Summary's failed test names were hidden at minimal, and the logger's blocks already name the failed tests.Fulldiffers fromFailuresonly through the result file, which doesn't exist yet.What is implemented instead:
AgentMode = Off | Auto | On.Auto(default) turns agent mode on when an AI agent is detected.AgentModeonly changes defaults, and an explicit setting always wins.ShowStdout/ShowStderr = Failed,StackTrace = Filtered,Verbosity = -1.ShowStdout/ShowStderr:Allsends output to the console as it arrives,Failedkeeps it only in the test result (where the logger shows it for failed tests),Nonedrops it.ConsoleOutstays as an alias.StackTrace = Filteredalso removesNUnit.Framework.Internalframes. In the repro, an async failure went from 12 frames to 3.AgentMode=Offbehaves as before.Measured on a repro with 26 tests (21 passing tests writing stdout, stderr and progress, 3 ignored, 2 failing):
OffOnThe result file and the console line with its path (comment above) are not part of this.
🤖 Made by @OsirisTerje with Claude