Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Output of Unit Tests running in VisualStudio

What I am trying to achieve is quite simple but I am probably missing something. All I want is to INSTATNLY see my tests logging in the Console window, I have tried

Console.WriteLine(...)

I have tried

Trace.WriteLine(...)

I have tried

Trace.Listeners.Add(new TextWriterTraceListener(Console.Out));
Trace.WriteLine(...)

This all show the output only AFTER the test has finished (and not in the Output console but as the "test output"), what I want is to see those logging as they happen. The way I am running the tests is using "Test-> Run-> All Tests" from the VS main menu.

The only way I can somewhat achieve what I want is by using

Debug.WriteLine(...)

But for this I have to run the tests in debug "Test -> Debug -> All Tests" and its kinda annoying...

Am I missing something?

like image 347
YWsecond Avatar asked Mar 14 '13 10:03

YWsecond


People also ask

How do I view test output in Visual Studio?

In the main menu of VS, choose View > Output, then within the Output pane, pick "Tests".

How do I run a unit test in Visual Studio?

Run tests in Test Explorer If Test Explorer is not visible, choose Test on the Visual Studio menu, choose Windows, and then choose Test Explorer (or press Ctrl + E, T). As you run, write, and rerun your tests, the Test Explorer displays the results in a default grouping of Project, Namespace, and Class.

What is unit test result?

A unit test provides a strict, written contract that the piece of code must satisfy. As a result, it affords several benefits. Unit testing finds problems early in the development cycle. This includes both bugs in the programmer's implementation and flaws or missing parts of the specification for the unit.


1 Answers

There is no way to achieve this except the one which you already know. MSTest adapter keeps caching the trace output and once test finishes, it emits it in the test output window.

This is a useful ask and I will pass this request to the mstest product owner in visual studio team.

like image 141
Aseem Bansal Avatar answered Jan 05 '23 02:01

Aseem Bansal