-
Notifications
You must be signed in to change notification settings - Fork 106
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 output from application is logged as warnings #1102
Comments
This is done by the Test Explorer, not the adapter. They do show this as a warning, as it is regarded as "wrong" to do console output in a test. In your particular case it is the SUT that outputs to the Console, and one can argue that it should be possible to turn that off, but you can't. On the other side, the Console output could have been mocked off, using something like : https://www.nuget.org/packages/WrapThat.System#readme-body-tab and info here https://hermit.no/wrapthat-system-wrappers-for-system-io-to-simplify-unit-testing/ |
@OsirisTerje, thank you very much for pointing out internal class Program
{
internal static void Main(string[] args)
{
Console.WriteLine("Hello, World!");
Console.Error.WriteLine("Hello, error stream!");
}
} [TestClass]
public class UnitTest1
{
[TestMethod]
public void TestMethod1()
{
Program.Main(new string[] { });
Assert.IsTrue(true);
}
} So, can we really be sure that the issue I observed is not related to NUnit? 😅 |
That was weird. I'll check this out! Thanks for checking this with MSTest. |
@Ravigneaux1 Can I bother you with creating a small repro solution containing both a NUnit and a MSTest project ? |
@OsirisTerje, sure thing! I've just created pull request #6. Please let me know if it doesn't meet your requirements. |
This is actually the result of a "feature" in NUnit. NUnit has a configurable console output. MSTest doesn't seem to have the same (or I haven't found it). NUnit has the following default setup: Notice it outputs both in the test results (2) and in the test output console pane (3). MSTest only outputs in (2). If you set the ConsoleOut=0 nothing should come out, but it seems the error message still comes out. That seems to be a bug though. I'll add a separate bug for that. This issue is useful as it is. |
@OsirisTerje, oh my, silly me was actually aware of the Anyway, thanks for pointing me in the right direction! I never really understood why sending the application's output to the standard error stream is the default, though. Should default to the standard output stream (value |
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 :-) |
@ravigneaux-1 Fixed in 4.6, beta here : https://www.myget.org/feed/nunit/package/nuget/NUnit3TestAdapter |
@OsirisTerje, thanks for your time and effort! 🙂 I see that console output from the application under test is not logged as warnings anymore when using the standard output stream ( Anyway, I'm a bit lost what would be the correct setup for what I have in mind... In my opinion, console output from the application under test should never be forwarded as warnings (it's perfectly valid for an application to write to the error stream) while at the same time it should be possible to emit info, warnings and errors from the test cases, e.g. to point out that there is an issue in the test system (not sure what would be the right way to do it such that each message type is properly displayed in the Test Explorer and the console...) 😵 |
Yes, the error stream should be , because it is then an error that is warned. I am not sure how one can separate between the two (app under test and test itself), since internally in NUnit the streams are just captured and directed into the console and error streams. And Test Explorer does not separate either.
NUnit (and any other framework too) executes the test. The SUT is just being called from the test itself. I am not sure if this is possible at all. The test may also invoke methods from other frameworks, and they may also output to the console, and how should the test know what is what? Perhaps if the application rerouted its own console out to something else (even null), then the only output would be from the test. That means it would be harder to test console output, but if that is wanted, one could reroute to a file, and include that. Thoughts? |
@OsirisTerje, done! I've submitted issue #1167 for discussion. Apologies for the late response, I didn't want to throw complaints without substance at you, so I had to evaluate and prepare a few things first... |
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()
).Steps to reproduce
Main
method from implicitprivate
tointernal
Write
to the standard output and/or standard error stream from within theMain
methodMyApp.csproj
:Main
method to the default test case:Version information
The text was updated successfully, but these errors were encountered: