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";

public class HelloWorldTest
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:

public class HelloWorldTest
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()


Comments (17)
  1. Roy Osherove says:

    Gosh darn it.

    I try to run the test I made through the test explorer but I keep getting the dreaded "Test Run configuration needed" dialog.

    Where am I supposed to get one of those?

  2. Roy – The only way that I know of how to get the .rcg file is to create a Test Project. I will follow up with the dev team and see if there is another way.


  3. Ben says:

    You could simplify that code by doing:

    using NUnit = Microsoft.VisualStudio.QualityTools.UnitTesting;

    using NUnit.Framework;

    using TestCase = TestClass;

    using TestMethod = Test;

    at the top.


    But seriously, why reinvent the wheel on this? I have no awesome thoughts of porting all of my NUnit-based tests over to this new framework. Why buck the community on this one?

  4. Ben says:

    or rather..

    using TestFixture = TestClass;


  5. Dietmar says:

    Both csUnit and NUnit use the same attributes for declaring test cases [TestFixture], test methods [Test] and setup/teardown operations [SetUp], [TearDown].

    IMHO I think it would be better and easier to use these well-known attributes in VS2005?!?

  6. Mike says:

    I really agree with Dietmar on his point about using the standard Attributes. Unless there is a really good reason this is a disservice to the community.

  7. Please stop the fragmentation of the testing tools market!

  8. peterchen says:

    Isn’t this what they call "diversity"?

  9. Hugo Batista says:

    We all want unit testing feature in base vs 2005 versions


Comments are closed.

Skip to main content