Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Console.WriteLine() does not write to console when runningdotnet test #343

Closed
rprouse opened this issue Jun 17, 2017 · 33 comments
Closed

Console.WriteLine() does not write to console when runningdotnet test #343

rprouse opened this issue Jun 17, 2017 · 33 comments

Comments

@rprouse
Copy link
Member

rprouse commented Jun 17, 2017

@ayoung commented on Thu Jun 15 2017

I'm running dotnet test targeting netcorapp1.1. Within the test I'm executing a console write but that text never makes it to the output on the screen.


@rprouse commented on Fri Jun 16 2017

Are you using dotnet-test-nunit or the alpha of the adapter for your tests? In other words, project.json or csproj? This issue needs to be moved to the correct repository.


@ayoung commented on Sat Jun 17 2017

i am using the alpha adapter. csproj.


@rprouse commented on Sat Jun 17 2017

Thanks, I am going to move to that repository then. Please track it there.

@cincuranet
Copy link

Any workaround for this for now?

@rprouse
Copy link
Member Author

rprouse commented Sep 16, 2017

Sorry, nothing yet.

@giggio
Copy link

giggio commented Nov 6, 2017

This makes showing the errors a pain. Microsoft is directing the problem to the test adapter implementers, see: microsoft/vstest#799

@sebwills
Copy link

I am finding that if a test is successful, its console output is not displayed. But if it fails, after the failure message and Stack Trace, the output contains a line "Standard Output Messages:" followed by the console output from that test alone. Is this behaviour deliberate? If so is it configurable?

@gerektoolhy
Copy link

Run into same issue as well. See #132 (comment)

@Thaina
Copy link

Thaina commented Feb 14, 2018

I have the same problem and would like this to be fixed too

@scriplit
Copy link

For info, "dotnet test -v n" adds a lot of crap to the console, but at least diplays the stdout lines.

@Thaina
Copy link

Thaina commented Feb 24, 2018

@scriplit And it is a lot of crap that really just a crap without anything useful

@rprouse
Copy link
Member Author

rprouse commented Feb 24, 2018

We can't add to the command line options for dotnet test and the adapter can't even get access to most of the command line options, so it makes it hard to configure, but we should probably be outputing to the console when the messages are received similar to we do in NUnit Console.

@dhowe
Copy link

dhowe commented May 17, 2018

Same issue... though for me I don't see stdout lines, even with "-v n" flag
Any update?

@chriswolf-nrg
Copy link

Why does NUnit-3 disable console output? It also seems to disable logging too. Is there a way to make NUnit not do that?

@jnm2
Copy link
Contributor

jnm2 commented Sep 23, 2018

Even though it can't access dotnet test arguments, one thing the adapter can do is read options from a .runsettings file.

@zcyemi
Copy link

zcyemi commented Jan 20, 2019

Same issue... though for me I don't see stdout lines, even with "-v n" flag
Any update?

Try use NUnit.Framework.TestContext.Progress.WriteLine(), it works for me with dotnet test.

@JustoSenka
Copy link

JustoSenka commented Feb 20, 2019

Well 'NUnit.Framework.TestContext.Progress.WriteLine()' could work it is tests which write to console. Bu we have no control of what the application we are testing writes to console. It's still a bug, seems to be trivial to fix, but nobody fixed it in years

@jnm2
Copy link
Contributor

jnm2 commented Feb 20, 2019

@OsirisTerje should this be up for grabs? Sounds like there's a possibility that this is trivial.

@OsirisTerje
Copy link
Member

OsirisTerje commented Feb 20, 2019

@jnm2 Anyone can grab this of course. Tip: Enable dump file, and look at what NUnit actually sends to the adapter. Anything going there is sent to the EventListener, and once there it can be sent anywhere.
Also, ensure you're running dotnet test with the -v n option

@richardthombs
Copy link

Can you please bump the priority of this a bit? Still no progress after nearly a year since the last comment.

@OsirisTerje
Copy link
Member

OsirisTerje commented Jan 28, 2020

@richardthombs Can you please check this alpha version: https://www.myget.org/feed/nunit/package/nuget/NUnit3TestAdapter/3.17.0-dev-01324

The console output is fixed there.

It's part of a rather big refactoring, all tests are green, but if you see something else then just report that.

Also ping @ayoung, @cincuranet , @giggio, @sebwills, @dariusdamalakas , @Thaina, @scriplit,@dhowe, @zcyemi,@JustoSenka

roji added a commit to roji/TestConsoleTests that referenced this issue Feb 22, 2020
@roji
Copy link

roji commented Feb 22, 2020

@OsirisTerje have just tested with NUnit3TestAdapter 3.17.0-dev-01324 and I still cannot see Console.WriteLine with dotnet test (on either Windows or Linux). Note that everything seems fine on all IDE test runners (Rider, VS).

Repo with the test: https://github.com/roji/TestConsoleTests/

@OsirisTerje
Copy link
Member

OsirisTerje commented Feb 22, 2020

@roji Just tried your repo, and I do see the correct output. Changed the console.writeline to say "Hello world from NUnit" and "Hello world from XUnit", and I do see the NUnit output, but not the XUnit output.
343-1

Please note that you need to have the verbosity set to normal. that is:

dotnet test -v n

@roji
Copy link

roji commented Feb 23, 2020

@OsirisTerje ah I see, thanks - with the verbosity set to normal I can see the message as well. Seems a bit questionable to not write output by default, but I'm guessing that's unrelated to NUnit.

@OsirisTerje
Copy link
Member

@roji Agree with the verbosity, that is the dotnet test default that imho should be normal, but for some reason is not. And as you assume, we can't do anything with that from the adapter side. Could be worthwhile an issue at the dotnet repo though.

@roji
Copy link

roji commented Feb 24, 2020

Opened dotnet/sdk#10706

@OsirisTerje
Copy link
Member

@roji Beta released on Nuget, see https://www.nuget.org/packages/NUnit3TestAdapter/3.17.0-beta.1 . Please check that it works :-)

@roji
Copy link

roji commented Apr 20, 2020

Great! Gave it a try, and I can confirm that I can see Console.WriteLine (when -v n is specified).

@giggio
Copy link

giggio commented Jun 27, 2020

I just tried it with 3.17.0-beta.2 and it is working fine (with -v n). Waiting for the stable release now.
I hope dotnet/sdk#10706 closes soon so this becomes better.

@OsirisTerje
Copy link
Member

@giggio Thanks!

@alfreql
Copy link

alfreql commented Dec 21, 2021

Hi I'm using net5.0, NUnit-3.13.2 and NUnit3TestAdapter-4.1.0 and Console.WriteLine("HELLO!!!") is not working. I still cannot see the output HELLO!!! on the console. I'm running on Windows like this: dotnet test SomeExample.sln -v n

@OsirisTerje
Copy link
Member

OsirisTerje commented Dec 21, 2021

@alfreql Yeah, this is annoying, see dotnet/sdk#10706 . You can get it out doing:

dotnet test v n --logger "Console;verbosity=normal"

alternatively, if you don't want the logger approach, change your code to use TestLogger.Progress.WriteLine, that will output with just the dotnet test -v n

@alfreql
Copy link

alfreql commented Dec 21, 2021

Thanks!!! Also without -v n works (and avoid some verbosity):
dotnet test SomeExample.sln --logger:"console;verbosity=normal"

@OsirisTerje
Copy link
Member

Hmm.... cool and right you are, never tried removing that one :-)

That means one could also set the logger in a .runsettings file, see https://docs.microsoft.com/en-us/visualstudio/test/configure-unit-tests-by-using-a-dot-runsettings-file?view=vs-2022#loggerrunsettings-element and then do

dotnet test -s .runsettings

The .runsettings would then be:

<?xml version="1.0" encoding="utf-8"?>
<RunSettings>
    <LoggerRunSettings>
        <Loggers>
            <Logger friendlyName="console" enabled="True">
                <Configuration>
                    <Verbosity>normal</Verbosity>
                </Configuration>
            </Logger>
        </Loggers>
    </LoggerRunSettings>
</RunSettings>

PS: If you only have the sln file in the folder, you don't need to specify it

@OsirisTerje
Copy link
Member

Just to have it said: There is something that happened, because the 3.17 DID output the Console, but right now it doesn't, neither for 3.17 or for 4.X.

Not sure what, but I'll look into it.

@OsirisTerje
Copy link
Member

This will be fixed in 4.2

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

No branches or pull requests