0

When I debug a unit-test with Visual Studio 2017, all the console output is logged and I can examine it by clicking the "Output"-link in the result box of the unit-test (I'm using the built-in Test-Explorer).

However, since I do log a lot to console at runtime which is even color coded so important stuff is more visible, I can't see this color coded output using the "Output"-link, because it's just plain black text on white background.

Is it possible that Visual Studio shows all the output directly in a console window when debugging the tests so I see the output as I would see it when actually running the application outside of a test?

Ravior
  • 561
  • 2
  • 9
  • 30
  • Do yourself a favor and only output anything when you see code misbehaving. Nobody is ever interested in "it works fine" output. There is only one color for "this is bad", doesn't matter if it is red or black. – Hans Passant Mar 07 '18 at 13:50
  • Thanks for the hint! In a simple environment, this could easily be followed. In an advanced environment, this can be achieved by filtering per log-level of course. And in a professional environment, with some requirements like audit-trailing, it is even wanted to log things that worked fine, just for the sake of knowing that it actually happend. Sadly, I'm rather in the latter environment and need to debug some code that does also do said audit-trailing. – Ravior Mar 07 '18 at 14:03
  • @Ravior, Do you get useful information for this issue? Would you please share the latest information about it? – Fletcher Mar 12 '18 at 01:46
  • Not yet, but I'm still looking into it. I will try out some of the answers soon. – Ravior Mar 13 '18 at 10:21
  • @Ravior, I look forward to hear from you. If you get any latest information, feel free to share it. – Fletcher Mar 15 '18 at 02:22

2 Answers2

1

You cannot (or it is very tricky at least) open a console window from a unit test - I've tried with the top 2 answers from the following post, and they didn't work: Show Console in Windows Application?

You can make the Debug.Write... methods write to the Console when you are running/debugging the application itself (not the unit tests) with this code, though:

ConsoleTraceListener listener = new ConsoleTraceListener();
Debug.Listeners.Add(listener);

Any calls to Debug.Write... methods after this code will also output to the console.

Boregore
  • 207
  • 1
  • 11
0

Standard output is the only way to display the test output, when we use some output method in our test like Debug.WriteLine(); Console.WriteLine(); etc. I also tried to change the font of the test output but it seems there is no that option is VS 2017, even someone though someone mentioned this before:

Is there a way to change the Font used in the VS2012 Test Output Window?

Similar case discussed in this thread, even some reply claimed that we could manually launch the console window, but they are 100% sure about it.

If you really need change the font or the color of the test output, in Visual Studio you go to Help -> Send feedback to VS developing team to provider your suggestion .

Fletcher
  • 422
  • 1
  • 6
  • 21