Welcome to MSDN Blogs Sign in | Join | Help

Using VSTS to do Test Driven Development

VSTS doesn't have a pure set of Test Driven Development features, but using the built-in refactoring support for C# you are able to get a good Test Driven Development experience in VSTS 2005. Test Driven Development is a methodology we greatly believe in at Microsoft, new Test Driven Development specific features might show up in future releases.

Here’s how you can use refactoring to generate shipping code from a Unit Test in VSTS. Let’s say, I need to test class A that has method “string GetData()”. I start from writing the test for it:

[TestClass]
public class ATest
{
   
[TestMethod
]
   
public void
GetDataTest()
   
{
      
A a = new A
();
      
string
s = a.GetData();
      
Assert.AreEqual("my data", s, "Wrong data returned!"
);
   }
}

I want to generate the A.GetData from this test. Well, since class A does not exist yet, I create it manually as:

public class A
{
}

All I have to do now is right-click a.GetData() in my test and select “Generate Method Stub” from context menu:

It generates the following code:

public class A
{
   internal string
GetData()
   {
      throw new Exception("The method or operation is not implemented."
);
   }
}

Now I can run the test and make sure it fails. Then I will implement GetData, run my test and fix the code, until the test passes.

Published Friday, July 29, 2005 6:19 PM by mkolt

Comments

# Link to Michael Koltachev's blog on how to do Test Driven Development using VSTS

Sunday, July 31, 2005 10:22 PM by VSTS Quality Tools

# Suggested Reading - 2005-07-31

Cleaning-out my “To Blog” file again…
Architects

Handling data in service oriented systemsEdward...
Monday, August 01, 2005 2:58 AM by Rob Caron's Blog - A Team System Nexus

# VSTS Links - 8/3/2005

Michael Koltachev - Using VSTS to do Test Driven Development

Michael shows you how to use VSTS to...
Wednesday, August 03, 2005 2:15 PM by Team System News

# Michael Kolt on Test Driven Development with Visual Studio Team System

Miachel Kolt has a nice short piece on leveraging the VSTS IDE to handle method creation for you as you...
Wednesday, August 03, 2005 3:21 PM by Kevin W. Hammond

# New and Notable 77

Wednesday, August 03, 2005 4:42 PM by Sam Gentile's Blog

# New and Notable 77

Wednesday, August 03, 2005 11:47 PM by Sam Gentile's Blog
Anonymous comments are disabled
 
Page view tracker