microsoft / vstest

Visual Studio Test Platform is the runner and engine that powers test explorer and vstest.console.
MIT License
869 stars 316 forks source link

Forward standard output of testhost #4998

Closed nohwnd closed 2 months ago

nohwnd commented 2 months ago

Description

When Tests write output using Console.WriteLine it may or might not be seen by the user, depending on which target framework they are using, which OS, and which testing framework.

When it is seen:

User is running .NET Framework tests in-process, is using vstest.console 17.6.3 or earlier, and is not using MSTest. User is running tests on Linux.

When it is not seen:

This pull request standardizes the output capturing and passing to parent processes via Informational TestMessage. This same mechanism is used by xUnit to send their [xUnit.net 00:00:00.11] Starting: xunit001 messages.

Two options are added and enabled by default:

<RunSettings>
    <RunConfiguration>
        <CaptureStandardOutput>true</CaptureStandardOutput>
        <ForwardStandardOutput>true</ForwardStandardOutput>
    </RunConfiguration>
</RunSettings>

CaptureStandardOutput enables output capturing by VSTest. When disabled the behavior returns to the one of 17.6.3 and earlier. ForwardStandardOutput enables output forwarding. When enabled it forwards output to VS.

When disabled, but CaptureStandardOutput is enabled it will suppress all output and return to behavior in 17.7.0 and newer.

Additionally two feature flags are added to allow easier global opt-out:

VSTEST_DISABLE_STANDARD_OUTPUT_CAPTURING
VSTEST_DISABLE_STANDARD_OUTPUT_FORWARDING

Setting them to 1 has the same effect as setting the above options to FALSE.

Related issue

Fix https://github.com/microsoft/vstest/issues/799 Fix https://github.com/microsoft/vstest/issues/4828 Fix https://github.com/microsoft/vstest/issues/4947

nohwnd commented 2 months ago

Draft because I want to add a test or two.

nohwnd commented 2 months ago

/azp run

azure-pipelines[bot] commented 2 months ago
Azure Pipelines successfully started running 1 pipeline(s).
nohwnd commented 2 months ago

We are capturing process output, if the test framework lets the output to pass through we will capture it. There is no cooperation from the framework needed, as long as the output is able to reach the process output.