Repository navigation
Console.WriteLine calls during dotnet test are not emitted to the console on Windows #799
Description
Activity
From Krzysztof Wicher (@krwq) on January 5, 2017 23:46
Jon Sequeira (@jonsequitur) You should probably be using Xunit's ITestOutputHelper. making Console.WriteLine forward to that might be slightly harder
From Jon Sequeira (@jonsequitur) on January 6, 2017 4:35
The issue that I was seeing was that this works on OS X but not on Windows.
I am seeing that too on windows. None of the Console.WriteLine from my tests gets printed out. We should not ask users to use special APIs to print to the console.
codito Faizan Ahmad (@Faizan2304) Can you guys take a look?
I think we should move this bug to the vstest repo.
Reacted by Rebecca Taylor, Damian Powell, AraHaan, Tomáš Koreň, Rony Dennis, Ben Collins, slyedav, Michael Brown, Vladimir Perevalov, Josh DeGraw and 13 moreI think this should be handled by adapters at some level. MSTest for instance captures and sends the console outputs to the runner, I think we are including them in trx logger, but not in the console. We can start showing them in console. cc: Faizan Ahmad (@Faizan2304)
There were a few requests to capture console output in xunit:
https://xunit.github.io/docs/capturing-output.html suggests to use IOutputHelper
xunit/xunit#1141Faizan2304 commented
on May 16, 2017 ContributorMore actionsFixed!!
Reacted by Leszek, Markus Doggweiler and Zoltán ZvaraFaizan Ahmad (@Faizan2304) Is it fixed in Visual Studio Community 2017 Version 15.2 (26430.15) Release? I still cannot get the output in the output window or the test explorer. I'm using xunit.
I also still do not see test output and would love to, please.
From
dotnet testoutput:Test ...Tests\bin\Debug\netcoreapp2.0\~.dll(.NETCoreApp,Version=v2.0) Microsoft (R) Test Execution Command Line Tool Version 15.3.0-preview-20170703-02and in csproj:
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0-preview-20170628-02" /> <PackageReference Include="xunit" Version="2.2.0" /> <PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" />(I am using preview version of VS and latest dotnet core from github)
Reacted by Neo Mxn0, Reilly Wood and Jeff TianSorry for the late reply. I missed this thread.
Zou Wei (@zwcloud): We have fixed it in vstest.console of version v15.3.0-preview-20170517-02 and it is part of Visual studio 2017 Update3 preview3. Please see below answer to see test output with xunit.Chris Rogus (@rogusdev) : How are you writing output from test method? Is it
Console.WriteLine?
If yes then it seems xunit doesn't support that.
There were a few requests to capture console output in xunit:
https://xunit.github.io/docs/capturing-output.html suggests to use IOutputHelper
xunit/xunit#1141Is it Console.WriteLine ?
If yes then it seems xunit doesn't support that.Yes. But Brad Wilson (@bradwilson) said in xunit#1141
There is no way to see that output with dotnet test because of limitations in the VSTest runner.
We do not capture stdout (users are free to use that if they so choose). Our output capture system pushes that information into the test result rather than to stdout. The TRX report may or may not generate reports which include "output" results (I don't personally know, since I have no knowledge of this format), but today there's no simple way today to get this output from dotnet test directly on the console.
Visual Studio's UI, on the other hand, offers ready access to "output", which is where this information is captured.
So.. could you fix or change the behaviour of VSTest runner to remove the limitaion?
Reacted by Cole TobinReacted by Justin ChaseZou Wei (@zwcloud):
We display what adapter sends in TestResult.Message Code here And hereIts the responsibility of adapter to fill console.WriteLine message in TestResult.Message.
But as you can see, Brad Wilson (@bradwilson) said in xunit#1141 that they are not capturing console output to test result
Users will use ITestOutputHelper to write output. That's what ends up in ITestResultMessage.Output. We do not capture any device like console, debug, or tracing.
In this case you have to follow this article. xunit is suggesting to use IOutputHelper to log your message.
Why the issue is closed if there is still no console output in tests?
It's kinda strange to have console test runner which doesn't show console output.
Reacted by Piotr Perak, Per Samuelsson, JB, Old man, Neutrino, Marcos Almeida, Fouad Roumieh, nopara73, Shane Gray, Keith Hall and 90 moreReacted by Justin Chase, olfek and DanBumping this in case anyone else comes along hoping to find an answer.
dotnet test -v nI learned that running the above will show the "Standard Output Messages:" that you would expect from Console.Write*. It does flood the terminal with information at build but at least is a solution for the time. "-v" is a Verbosity argument. "n" represents "normal". Refer here for more information.
I use this with a .NET Core Unit / Integration test projects running NUnit.
Reacted by Alejandro J. C De Baca, Jaime Olivares, Thomas Wolff, woellij, Anil Vangari, Keith Hill, Matías G. Rodriguez, Miguel Ballén, Mark Richardson, Hendra Wong and 10 moreReacted by Dan, Steve, Matt Painter, Charlie Rose, thosch1800, Massimiliano Kraus, Mike Thompson, pluma9 and Nathan Bodie56 remaining items
Brad Wilson (@bradwilson) What results? There have been no results in 6 years.
Reacted by Jeff, Dan, martinog2, Sam Webb, TeamDman and npodbielskiJeff (@peabnuts123) I was on a long leave and I am just back. I will read all this thread and try to give some information/ask for plan about this.
Thank you for making this point Jeff (@peabnuts123), it's unbelievable that such a major framework should be broken in such fundamental way for so long, and on Windows of all platforms. I was mortified when I found out our Mac developers had been having a completely different experience with this all this time.
Reacted by martinog2 and Robin MunnWow, on a leave for 6 years... And the issue didn't get assigned to anyone else...
Reacted by martinog2, Stefan Sechelmann, Jeff Stamerjohn, David Andersen, Sam Webb, npodbielski and Duane KingReacted by npodbielski, Vlad Rudenko and Alex NolascoIt would be great if this discrepancy could be resolved. I'm surprised it's been outstanding for so long. This is making it harder for me to debug issues during testing for libraries that I do not govern, and as such cannot modify their methods of outputting to the console; I can see their logs in Linux, but not Windows.
Reacted by IngmarPaetzold and pluma9I am on Windows, and when I first setup xunit a few days ago (using the
ITestOutputHelper, I did not need to pass extra args todotnet test... not sure what changed, but now nothing is output unless I add the--logger "console;verbosity=detailed"arg.Kind of weird how it changed. Unfortunately I cannot pinpoint what could have possibly affected it.
Is there a way to make
--logger "console;verbosity=detailed"the default?Reacted by Konrad Abicht and Omair MajidHello. Is there any update on this egregious seven year old bug affecting users running on Windows, a platform I understand the project owner has some interest in?
Reacted by Nate Bross, TeamDman, pluma9, lewis and Josh LupoReacted by npodbielskiConsole log debugging is a real pain now.
It's not always possible to inject
IOutputHelperinto a class.pluma9 (@pluma9) this should work without needing to pass in ioutputhelper https://github.com/SimonCropp/XunitContext/
Reacted by Nicholas Preston and fw-aaronlit's amazing that after an hour of pulling my hair out as to why this wasn't working, I'm back to using linux on windows to debug a windows application. Microsoft will be Microsoft.
Reacted by npodbielski, Alex Nolasco, Alexander Krylkov, Nikita Starostin and mick-biotonixReacted by fw-aaronl and Nikita Starostin
From Jon Sequeira (@jonsequitur) on December 15, 2016 19:10
Steps to reproduce
Console.WriteLinecall in a test, .e.gGivenThatIWantToMigrateTestApps.ItMigratesRootProjectAndReferencesdotnet test --test-case-filter "FullyQualifiedName=Microsoft.DotNet.Migration.Tests.GivenThatIWantToMigrateTestApps.ItMigratesRootProjectAndR eferences"Expected behavior
The string passed to Console.WriteLine appears in console output.
Actual behavior
Environment data
dotnet --infooutput:.NET Command Line Tools (1.0.0-preview5-004253)
Product Information:
Version: 1.0.0-preview5-004253
Commit SHA-1 hash: 0caae96daf
Runtime Environment:
OS Name: Windows
OS Version: 10.0.14393
OS Platform: Windows
RID: win10-x64
Base Path: C:\dev\github\cli\artifacts\win10-x64\stage2\sdk\1.0.0-preview5-004253
Copied from original issue: dotnet/cli#5033