Race Troubleshooting Using The Console Output In VSTS

It must be my week of discovering the obvious. The other day I was troubleshooting a race condition in my code. I had a unit test that faithfully reproduced the error, but just looking at the code involved didn't produce any sudden insights into its reasons. The nasty thing about race conditions (and multi-threaded code in general) is that you can't debug them, since the debuger influences the race.

Sometimes, you can troubleshoot race conditions by tracing strategic points in the code, and sometimes it doesn't work, since even tracing statements influence the race. In my particular case, tracing didn't disrupt my race condition, so the only problem left was how I could view that output as easily as possible. Since I was using VSTS unit tests from within Visual Studio 2005, I was hoping my Console output would be in the Output window, but no such luck. Then, in a rare case of inspiration, I double-clicked on the test in the Test Results window and got a window similar to this one (which is a mock-up, I admit):

Notice the highlighted Standard Console Output.

It's so simple that I wonder I never discovered this feature before, but now that I know it exists, I know how to troubleshoot race conditions reproduced in unit tests the next time I have to deal with multi-dreaded code 🙂

Comments (4)

  1. Roey says:


    I send alot of output to ‘standard console output’ and its difficut to find something there.

    Do u know if there any way to print to ‘standard console output’ with color or bold or other font?

    I want to print with color in case of failure in a middle of the test and after the test was ended to look for the colored line and see whats the problem..

    if u do know how plz send it to my mail:


    Thanks in advance,


  2. ploeh says:

    Hi Roey

    Thank you for your question. The answer is both yes and no.

    While the Console API allows you to define color (e.g. via Console.ForegroundColor), there’s no guarantee that the console sink will pick it up. Both the Command Prompt and PowerShell respect and display the color defined via the API, but VS, unfortunately, does not.

    So your best option is probably resorting to indentation, special characters, and/or upper case.

  3. Gilda says:

    Cool! Thanks! I was wondering where the obvious was…

Skip to main content