My first unit test in Visual Studio Team System

As usual when you sit down and write your first bit of code in a new language or in this case a new unit testing framework what else would you write other then the tested version of Hello World (thanks to Scott Densmore). In this case the unit testing tool is part of the Visual Studio Team System that was announced at TechEd last week in San Diego. The example shown here uses the tech preview that was distributed to attendees.

using Microsoft.VisualStudio.QualityTools.UnitTesting.Framework;

public class HelloWorld
{
    public static string HelloWorldString()
    {
        return "Hello World";
    }
}  

[TestClass]
public class HelloWorldTest
{
    [TestMethod]
    public void HelloWorldStringTest()
    {
        string expected = "Hello World";
        Assert.AreEqual(expected, HelloWorld.HelloWorldString());
    }
}   

For those of us familiar with xUnit frameworks (JUnit, NUnit, etc) you will find a lot of similarities and much to like.

When I run the test I get the following result:

HelloWorldStringTest: Passed, Duration: 00:00:00.0924109

If I was to change the test to the following:

[TestClass]
public class HelloWorldTest
{
    [TestMethod]
    public void HelloWorldStringTest()
    {
        string expected = "Hello World Again";
        Assert.AreEqual(expected, HelloWorld.HelloWorldString());
    }
}

When I run this test I get the following result:

HelloWorldStringTest: Failed, Duration: 00:00:00.3460624

Assert.AreEqual failed. Expected:<Hello World Again>, Actual:<Hello World>.
at HelloWorldTest.HelloWorldStringTest()