Visual Studio Express 2013: Program output in unit tests (console, debug etc.)

Frank H. picture Frank H. · Sep 11, 2014 · Viewed 15.6k times · Source

I'm really banging my head against the wall here. Is it so hard to get program output in Visual Studio (Express 2013)? When writing code, I find it absolutely essential to be able to print out the values of variables, operations etc. while working and troubleshooting.

In Java and Eclipse, the System.out.println() allways works, printing to the IDE console. When writing C programs I allways use the console, so echoing anything is no problem. However, in VS Express 2013 I can't seem to get any output.

Can the problem be related to the fact that I'm writing unit tests, and not "normal" executable programs? If so, is there some way to get VS to show program output in unit test classes? I've tried using debug, but that doesn't show anything either. Thinking that there's a config problem, I've looked for solutions to debug messages not showing, but none of the options I've found (in here or other places) seem to help.

Or, of course - if there's another commonly used method for checking program values, output etc. while writing code in VS/C#, I'd like to hear about it :-)

Anyone got any ideas? And please, if the question is too unclear or something, tell me and I'll fix it.

NB: I'm using unit test classes for functional testing, in case someone wants to point out what I should and and shouldn't do with unit tests.

EDIT 1: I forgot to mention that I'm not able to run the code with "Start: Debug". If I try, I get this error: "A project with an Output Type of Class Library cannot be started directly." (The unit test project uses classes in another project, which i a class library project.) This is, of course, because I have no executable project in the solution. The way I run it is to run the selected test, from the Test Explorer.

EDIT 2: Code:

using System;
using System.Diagnostics;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using WordpressAutomation;

namespace WordpressTests
{

    [TestClass]
    public class LoginTests : WordpressTest {

        [TestMethod]
        public void AdminUserCanLogIn() {

            System.Diagnostics.Debug.WriteLine("Something...");
            System.Diagnostics.Trace.WriteLine("Something...");
        }
    }
}

Answer

Jehof picture Jehof · Sep 11, 2014

The TestExplorer of Visual Studio has a separate output window. It does not write to the default Output of Visual Studio (I do not know if it is configurable)

You have to select the Test you want to see the output in the TestExplorer. If Test has some Output you should see a Hyperlink "Output". Clicking that will open a new tab displaying the output of the Test.

enter image description here

The displayed messages are all written by Console.WriteLine.

I´m using Visual Studio 2013 Professional. I´m not sure if the Express version works diffrent.