(Edit: Sorry for the misleading title. Indeed, this is more of an introduction to unit testing in 2005 then actual TDDing in it – Cory)
Over the weekend I got VS2005 beta installed on a virtual PC. While I know there have been a lot of changes to the IDE, I was most interested in the Testing features that were added to it. Here are some first impressions.
First, I fired up the IDE. I noticed that when I went to create a new Solution, I had the option of creating a Test Project:
Since I don’t normally start my projects, I filed that away. I decided to start with a Windows Application. After I created the solution, I added a Test Project to it, and ended up with something like:
After adding the Test Project, something really interesting happened. An AuthoringTests.txt file popped up, and it had instructions for how to get the tests up and running. About a minute later I had my first test written, which is the first test I usually use in my NUnit methods:
[TestMethod]
public void TestMethod1()
{
Assert.IsTrue(true, "This Works");
}
I noticed they also provide Initialize()
and Cleanup()
methods (tagged by the custom attributes [TestInitialize()]
and [TestCleanup()]
respectively). So it looked something like:
Great! Now how do I run it? The AuthoringTests readme said that tests could be run from the Test View window and the Test Manager window. Great. Where the heck is that? Ooh shiny new Test Menu option!
Zipping down to the Manage and Execute Tests option pulls up the Test Manager. From there, I was able to click on Run Tests, and get my first Green Bar (sorta)!
So I guess Green Checkies will have to do.
All in all, not a bad first start. The tests seem to take a little while to compile, but I am running it in a Virtual PC giving it 512MB of RAM, and it is Beta, so both of those together I’m sure have something to do with it. It was exciting seeing the work that went into it, going so far as to provide the AuthoringTests instructions. I don’t think I’m quite ready to replace NUnit with it, but it’s great to see some progress from Microsoft on the issue!
For those interested, according to the AuthoringTests.txt file, these are the Test Types you can create with Visual Studio Team Test:
Test Types
———-
Visual Studio Team Test allows you to create a number of different test types:Generic test: A generic test is an existing program wrapped to function as a test in Visual Studio. Three examples of generic tests are the following:
– Wrap an existing test that adheres to the Visual Studio return-code interface.
– Wrap an existing test harness that adheres to the Visual Studio result-data interface.
– Wrap a general program to obtain specific functionality during a test scenario.Manual test: The Manual Test type is used when the test tasks are to be completed by a test engineer as opposed to an automated script.
Ordered test: Use an ordered test to execute a set of tests in an order you specify.
Unit test: Use a unit test to create a programmatic test in C++, Visual C# or Visual Basic that exercises source code. A unit test calls the methods of a class, passing suitable parameters, and verifies that the returned value is what you expect.
Hi, Cory,
I’ve been down the road you’re just starting, and I have some interesting conclusions. You might want to check out these posts on my blog:
http://www.agileprogrammer.com/oneagilecoder/archive/2005/06/30/5281.aspx
http://www.agileprogrammer.com/oneagilecoder/archive/2005/04/22/3267.aspx
I personally prefer the Resharper unit test runner and toolset for running my tests. They let me get into a better TDD rhythm than the VSTS tools do. If you’d like to chat more about this, email me through my blog and we can chat more.
— bab
Thanks Brian! I figured someone out there would have gone down it already, thanks for the links!
Hey Cory,
A bit of a confusing title… not much TDD here… Good summary on plain old testing in VS 2005 though.
-s
I just did something similar, and my conclustion is exactly the opposite.
In my opinion, VS cannot be used for testing complex stuff.
See here for the reasons:
http://www.ayende.com/Blog/2005/09/30/VisualStudio2005UnfitForTesting.aspx
what a great site and informative posts, I will add a backlink and bookmark your site. Keep up the good work!
I’m Out! :)