Visual Studio 2010 and Test Driven Development
        Posted  
        
            by devoured elysium
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by devoured elysium
        
        
        
        Published on 2010-05-16T17:33:25Z
        Indexed on 
            2010/05/16
            17:40 UTC
        
        
        Read the original article
        Hit count: 260
        
I'm making my first steps in Test Driven Development with Visual Studio. I have some questions regarding how to implement generic classes with VS 2010.
First, let's say I want to implement my own version of an ArrayList. I start by creating the following test (I'm using in this case MSTest):
[TestMethod]
public void Add_10_Items_Remove_10_Items_Check_Size_Is_Zero() {
    var myArrayList = new MyArrayList<int>();
    for (int i = 0; i < 10; ++i) {
        myArrayList.Add(i);
    }
    for (int i = 0; i < 10; ++i) {
        myArrayList.RemoveAt(0);
    }
    int expected = 0;
    int actual = myArrayList.Size;
    Assert.AreEqual(expected, actual);
}
I'm using VS 2010 ability to hit
ctrl + .
and have it implement classes/methods on the go.
- I have been getting some trouble when implementing generic classes. For example, when I define an 
.Add(10)method, VS doesn't know if I intend a generic method(as the class is generic) or anAdd(int number)method. Is there any way to differentiate this? - The same can happen with return types. Let's assume I'm implementing a 
MyStackstack and I want to test if after I push and element and pop it, the stack is still empty. We all know pop should return something, but usually, the code of this test shouldn't care for it. Visual Studio would then think that pop is a void method, which in fact is not what one would want. How to deal with this? For each method, should I start by making tests that are "very specific" such as is obvious the method should return something so I don't get this kind of ambiguity? Even if not using the result, should I have something likeint popValue = myStack.Pop()? - How should I do tests to generic classes? Only test with one generic kind of type? I have been using 
ints, as they are easy to use, but should I also test with different kinds of objects? How do you usually approach this? - I see there is a popular tool called TestDriven for .NET. With VS 2010 release, is it still useful, or a lot of its features are now part of VS 2010, rendering it kinda useless?
 
Thanks
© Stack Overflow or respective owner