Welcome to MSDN Blogs Sign in | Join | Help

James Newkirk's Blog

Adding to the kipple... One post at a time.
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()

 

Posted: Wednesday, June 02, 2004 3:56 PM by jamesnewkirk

Comments

RobCaron's Blog said:

# June 2, 2004 3:31 PM

Roy Osherove said:

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?
# June 2, 2004 4:55 PM

Kevin Dente's RantLog said:

# June 2, 2004 11:58 PM

James Newkirk said:

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.

Jim
# June 2, 2004 9:05 PM

Ben said:

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?
# June 3, 2004 1:45 PM

Ben said:

or rather..
using TestFixture = TestClass;

:)
# June 3, 2004 1:45 PM

Todd Kitta's Blog said:

# June 3, 2004 8:04 PM

Dietmar said:

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?!?
# June 4, 2004 4:18 AM

Geek Noise said:

# June 6, 2004 11:37 PM

Mike said:

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.

# June 8, 2004 2:06 PM

NUnitAddin said:

# June 14, 2004 6:58 AM

NUnitAddin said:

# June 14, 2004 7:00 AM

Darrell Norton's Blog said:

Please stop the fragmentation of the testing tools market!
# June 14, 2004 10:22 AM

James Newkirk's Blog said:

# June 16, 2004 8:48 PM

James Newkirk's Blog said:

# June 16, 2004 8:52 PM

peterchen said:

Isn't this what they call "diversity"?
# June 17, 2004 12:59 AM

Hugo Batista said:

We all want unit testing feature in base vs 2005 versions
see http://hugobatista.dotnetx.org/archive/2004/06/30/159.aspx
# June 30, 2004 6:12 AM
Anonymous comments are disabled
Page view tracker