C# – Beginners introduction to unit testing in Visual Studio 2008

cunit testingvisual-studio-2008

I'm a self-taught developer and my experience is all in small applications that I've developed.

I'm currently working on an application that I've made public, and I've realized that I need to start doing good unit testing to catch regressions and generally make sure everything works.

I've read up on a previous question. I would like to know if there are any resources online specifically dealing with C# unit testing in Visual Studio 2008, preferably with examples.

EDIT: I'm using Visual Studio 2008 Professional for Windows applications, no web development.

Best Answer

You don't specify which flavor of VS2008 you are using. If it is Pro or above, then MSTest is bundled, but a lot of people have issues with it - it isn't always very intuitive, and it takes far too much setup to do simple things like coverage / file deployment.

A walkthrough is here.

As a recommendation, I suggest using VS2008 with NUnit (free) and TestDriven.NET (not free). It takes away all the pain, allowing you to just write simple things like:

[TestFixture]
public class Foo {
    [Test]
    public void Bar() {
        Assert.AreEqual(2, 1+1);
    }
}

Then just right-click (on the class, on the method, on the project, on the solution) and use the Test options that TestDriven.NET provides, including (if you have MSTest) "Test With -> Team Coverage", which runs your NUnit tests with the MSTest coverage tools, including giving the colorization back into the IDE to show which lines executed. No messing with "testrunconfig" and the other files that MSTest wants you to use.

Related Topic