question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Console output from application is logged as warnings

See original GitHub issue

Summary

When writing console output from the application under test, the output is displayed as a warning in the Visual Studio Test Explorer. This holds true both for the standard output stream (Console.Out.Write()) as well as for the standard error stream (Console.Error.Write()).

internal class Program
{
    internal static void Main(string[] args)
    {
        Console.WriteLine("Hello, World!");
        Console.Error.WriteLine("Hello, error stream!");
    }
}

image

Steps to reproduce

  1. Create a .NET console application project (“MyApp”)
  2. Change the protection level of the Main method from implicit private to internal
  3. Write to the standard output and/or standard error stream from within the Main method
  4. Create an NUnit test project (“MyApp.Tests”)
  5. Add a project reference from the test project to the application project
  6. Make internals of the application project visible to the test project by editing MyApp.csproj:
    <ItemGroup>
      <InternalsVisibleTo Include="MyApp.Tests"/>
    </ItemGroup>
    
  7. Add invocation of the Main method to the default test case:
    [Test]
    public void Test1()
    {
        Program.Main(new string[] { });
        Assert.Pass();
    }
    
  8. Run the tests in Visual Studio’s Test Explorer
  9. Observe the reported warning(s) in the Test Explorer

Version information

  • NUnit 3.13.3
  • NUnit3TestAdapter 4.4.2
  • Visual Studio Community 2022 (64-bit), version 17.5.0
  • Target framework: .NET 6.0

Issue Analytics

  • State:closed
  • Created 4 months ago
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
OsirisTerjecommented, Jul 5, 2023

I think the reason is historical. There was something many years ago that only error streams were displayed, so that started it. And in order not to break people who used that to get stuff into their CI logs, we kept it that way, but added the ConsoleOut. The default however, should have been changed, as you point out, so next breaking version I’ll get that done 😃

1reaction
OsirisTerjecommented, May 31, 2023

That was weird. I’ll check this out! Thanks for checking this with MSTest.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Warning in System.out when an error is logged in a custom ...
If an errors is logged, I would like to get a warning in the System.out with a notice to take a look at...
Read more >
Log messages in the Console - Chrome Developers
Click the Log Warning button in the demo. Abandon Hope All Ye Who Enter gets logged to the Console. Messages formatted like this...
Read more >
Log messages in the Console tool - Microsoft Edge
Console messages examples: log, info, error, and warn. The Console object has several levels of message-logging methods: console.log - Prints ...
Read more >
console: warn() method - Web APIs | MDN
The console.warn() method outputs a warning message to the Web console.
Read more >
Don't let ASP.NET Core Console Logging Slow your App down
NET Core 2.x Console logging is very, very slow when it is set to Information or worse Debug . The default ASP.NET Core...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found