Skip to content

Output settings for AI agents, aligned with Microsoft.Testing.Platform #1515

In review

Description

@OsirisTerje

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-stderr from All to Failed.

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

  1. One AgentMode setting 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.

    AgentMode For 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 as Off. 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 Failures Full run, including passed tests

    All levels except Off: no banner or informational lines, ShowStdout/ShowStderr = Failed, ReasonMessage only for skipped and failed tests, and one line with the result file path.

    Detection for Auto uses 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. Failures is the detected default because an agent that runs tests usually wants to know what broke.

    With Auto as the default, a human running dotnet test in an AI tool's terminal also gets the shorter output. MTP does the same. AgentMode=Off restores today's output.

  2. Replace ConsoleOut with ShowStdout/ShowStderr = All | Failed | None, the same names and values as MTP.

    • Failed needs the output buffered per test until the result is known. The listener already collects OutputNodes per test ID.
    • Keep ConsoleOut as a deprecated alias: 0 = None, 1 and 2 = All. Consider whether the warning level (2) is still needed.
    • In agent mode, the default is Failed, as in MTP.
  3. Suppress the banner and informational lines in agent mode. That is the same as Verbosity = -1, but only as a default. An explicit Verbosity wins.

  4. Send ReasonMessage only for skipped, ignored and inconclusive tests, and for failed tests when ShowStdout = Failed. It should not be sent for passed tests in Failed mode.

  5. Stack traces: the framework's StackFilter already removes NUnit's own frames. Check whether the remaining frames (async state machine and System.Runtime frames) are still noise for agents. If they are, add StackTrace = Full | Filtered | None to replace the two booleans.

  6. 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

Activity

  1. OsirisTerje commented on Oct 23, 2026

    @OsirisTerje
    MemberAuthor

    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.

    Aspect Console output Result file
    Control over format Partial. The VSTest logger or MTP draws it. Full. NUnit owns the schema.
    Same in VSTest and MTP No, two different renderers Yes
    Agent sees it Always, no extra step Only if it knows the file exists and where it is
    Short vs detailed Must be chosen with settings before the run One file; the agent selects what it needs (jq)
    Mixed with other output Yes: build output, other loggers, warnings No
    Token cost Paid on every run Paid only when the agent reads it

    Proposal: both, each with its own job.

    1. Result file (JSON). It carries the data: failures by default, with an option for the full run. It uses the JSON serializer planned in the framework, the same schema as the NUnit XML. The adapter already has the mechanism for this through TestOutputXml/OutputXmlFolderMode.
    2. Console. Only a summary line, the failures, and one line with the path to the file, for example NUnit results: <path>. Without that line, agents rarely find the file. This is the most important part of the design.
    3. All console settings in this issue stay as proposed, items 1 to 6. The file adds to them; it doesn't replace them. A file is not always possible or practical. Some CI systems only keep the console log. Users who don't use agents also benefit from a shorter console.

    Points the design must handle:

    • Stale files. A file from a previous run can mislead the agent. Overwrite the file on every run, and include a run timestamp in it.
    • Many files. There is one per test assembly and target framework. Use a fixed folder (the results directory) with predictable file names, or write a small index file.
    • Build failures. If the build fails, no tests run and no file is written. The console is then the only source, and the agent must not read an old file. Same fix as stale files.
  2. OsirisTerje commented on Nov 23, 2026

    @OsirisTerje
    MemberAuthor

    Two changes to the proposal, made while implementing it.

    Point 4. In agent mode (ShowStdout = Failed), ReasonMessage is 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 with MapWarningTo=Failed the 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. AgentMode is only a preset, and the individual settings are independent of it. Summary now presets ShowStdout/ShowStderr = None, not Failed, so it stays at counts and failed test names. Summary with an explicit ShowStdout=Failed adds the output and reason of failed tests.

    🤖 Made by @OsirisTerje with Claude

  3. OsirisTerje commented on Nov 23, 2026

    @OsirisTerje
    MemberAuthor

    Narrowing after measuring. This replaces the Summary part 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:

    • The counts line was hidden at minimal, and the logger already prints 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.
    • Output of failed tests sent by the adapter appeared twice, once from the adapter and once in the logger's block.
    • Full differs from Failures only through the result file, which doesn't exist yet.

    What is implemented instead:

    1. AgentMode = Off | Auto | On. Auto (default) turns agent mode on when an AI agent is detected. AgentMode only changes defaults, and an explicit setting always wins.
    2. Agent defaults: ShowStdout/ShowStderr = Failed, StackTrace = Filtered, Verbosity = -1.
    3. ShowStdout/ShowStderr: All sends output to the console as it arrives, Failed keeps it only in the test result (where the logger shows it for failed tests), None drops it. ConsoleOut stays as an alias.
    4. StackTrace = Filtered also removes NUnit.Framework.Internal frames. In the repro, an async failure went from 12 frames to 3.
    5. AgentMode=Off behaves as before.

    Measured on a repro with 26 tests (21 passing tests writing stdout, stderr and progress, 3 ignored, 2 failing):

    Logger verbosity Off On Saved
    minimal (default) 67 lines, 2692 chars 32 lines, 1196 chars 56 %
    normal 163 lines, 4951 chars 58 lines, 1844 chars 63 %

    The result file and the console line with its path (comment above) are not part of this.

    🤖 Made by @OsirisTerje with Claude

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions