Search code examples
c#unit-testingvisual-studio-2013outputvisual-studio-express

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


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...");
        }
    }
}

Solution

  • I don't really like answering my own question, since it seems kind of "dishonest". However, it's been quiet for a while, and I don't think there are other answers.

    The most practical solution is to create another project, for example a console project, where you create all the output. It might not communicate directly with the unit tests, but since the test framework I'm developing in this specific example consists of functional tests speaking to class libraries, it's possible to use a separate project in the solution.

    So, to summarize, the solution consists of: - A unit test project, with the actual tests - A class library project with the framework logic - A console project for testing classes in the class library, or non-unit test classes in the unit test project.