dotnet / sdk

Core functionality needed to create .NET Core projects, that is shared between Visual Studio and CLI
https://dot.net/core
MIT License
2.71k stars 1.06k forks source link

Consider outputting test standard output without explicit verbosity option #10706

Open roji opened 4 years ago

roji commented 4 years ago

Currently, Console.WriteLine calls in tests don't appear in dotnet test output unless normal verbosity is set (i.e. dotnet test -v n). This is extremely undiscoverable, especially since a reasonable assumption is for the default verbosity to be normal (the docs, mentioning only v2.1 and dotnet test -h say nothing about the default value for verbosity). It seems reasonable for Console.WriteLine to be shown by default without any switches.

See https://github.com/nunit/nunit3-vs-adapter/issues/343#issuecomment-589968287 for an NUnit issue on this and a test repo at https://github.com/roji/TestConsoleTests.

brcaswell commented 4 years ago

well the docs should be clarified on (using the feedback on them for that concern), that seems reasonable;

but this notion that verbose is on by default, or that Console.Write shouldn't be considered verbose in the context of Exception handling based test runners, isn't really a 'reasonable' expectation to have.

brcaswell commented 4 years ago

Perhaps the underline issue, or consideration, here relates to debugging efforts\workflows.

I don't use Console.Write at all, because I debug my unit tests in my IDE. And I wouldn't expect debugging code efforts to remain in the code base (or committed up) either way.

Or maybe I'm being presumptuous on that reasoning..

roji commented 4 years ago

@brcaswell it's obviously somewhat subjective whether the expectation for Console.WriteLine to appear by default is reasonable or not - but see this related xunit test with lots of user attention: https://github.com/microsoft/vstest/issues/799#issuecomment-326538698.

Note also that Console.WriteLine does appear when running under IDEs (VS test runner, Resharper). Also, the fact that you don't expect debugging code efforts to remain in the code base (i.e. Console.WriteLine) doesn't really have anything to do with whether they should be displayed or swallowed. The usual scenario here is an investigation/debugging effort where Console.WriteLine can be useful to quickly expose some information.

stvpalumbo commented 4 years ago

Also it is sometimes the only way in which to get environmental information like when running on a CI machine.

moh-hassan commented 4 years ago

In Windows, Running dotnete test from within Powershell Console like Powershell ISE or Package Console Manager in VS (tested in vs 2019) capture all Console.WriteLine used inside Xunit project or in source code. here script:

# powershell ISE console
cls
cd "path\to\test\project"
dotnet test

Note: Terminal Powershell can't capture output, use Powershell ISE

duaneking commented 3 months ago

The default expectation is that output happens, because that's how Console.Write* works normally.

This not working is technically breaking parts of the BCL, since defaults are not to redirect it or hide it.

The person who is advocating for this to be hidden by default is wrong.