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

How to log to Visual Studio IDE output window #1389

Closed
suntong opened this issue Jan 24, 2018 · 6 comments
Closed

How to log to Visual Studio IDE output window #1389

suntong opened this issue Jan 24, 2018 · 6 comments
Labels

Comments

@suntong
Copy link

suntong commented Jan 24, 2018

Just a simple noob question,

How to log to Visual Studio IDE output window?

I have a NUnit test, and I want to log some info to Visual Studio IDE output window during test execution. I've traced NUnit's own logging (to Visual Studio IDE output) to this project, but I can't make it works myself. E.g., I tried, among many other things,

Microsoft.VisualStudio.TestTools.UnitTesting.Logging.Logger.LogMessage("My own IDE output window log message");

but none is working for me.

Or, what IMessageLogger I should use (that is for Visual Studio IDE output), when initializing my own logger like the following?

https://github.com/nunit/nunit3-vs-adapter/blob/d8943d87ecccc097224494f905df287d79f097b3/src/NUnitTestAdapter/NUnitTestAdapter.cs#L121

Please help. Thanks!

@pvlakshm
Copy link
Contributor

pvlakshm commented Jan 31, 2018

Not sure I understand ...
If you use Console.Writeline you should see the emitted text in the Visual Studio Test Explorer's Output link.

Or, you can use a TextWriter ...

    System.IO.TextWriter t = TestContext.Out;
    t.WriteLine("using TextWriter");

Here too you should see the emitted text in the Visual Studio Test Explorer's Output link.

@suntong
Copy link
Author

suntong commented Jan 31, 2018

First, I want to log some info to Visual Studio IDE output window, check this out:

2018-01-31 09_48_10-easyuxautomation - microsoft visual studio

Second, I want to log them during test execution, not debugging.

NUnit's own logging is able to do it, logging to Visual Studio IDE output, but I'm not clear how. Hence the questions in OP.

This is during NUnit's unit test, where there is no console to write to. Console.WriteLine() does not write to Visual Studio IDE's output window. I just double-checked it.

Neither is the TextWriter, I just tried the above sample code but it is not logging to Visual Studio IDE output either:

2018-01-31 10_02_15-easyuxautomation - microsoft visual studio

Thx.

@acesiddhu
Copy link
Contributor

@suntong there is only one way today (and we don't want any other message to flow in test output window because it will have too many messages in the window which will confuse users
The only way (and I suggest we use that only for debugging) is Console.Error.WriteLine("test");

Normal Console.WriteLine("") messages wont flow to test window output. but they will flow to output of test case
image

@suntong
Copy link
Author

suntong commented Feb 6, 2018

That looks like a normal Unit test instead of a NUnit test, which is easy to write to (using Debug.WriteLine) because of that "Output" link. A NUnit test doesn't have that:

image

That's why I need to write to the Visual Studio IDE output window as posted above:

2018-01-31 09_48_10-easyuxautomation - microsoft visual studio

@acesiddhu
Copy link
Contributor

it is a nunit test

using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace nunit
{
public class Class1
{
[Test]
public void Test1()
{
// Console.Error.WriteLine("test"); // this prints in output window
Console.WriteLine("test"); // this shows in test window output as image attached in my previous reply
}
}
}

@suntong
Copy link
Author

suntong commented Feb 6, 2018

Gotya! Thanks a lot for helping!!!

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

No branches or pull requests

3 participants