Tutorials » VSTT tutorials »

Sample project for unit testing


In this chanpter, we will create a sample project and try some of the unit testing features available in Visual Studio 2008.


Let us create a sample project to illustrate the unit testing features in Team Test.
Open Visual Studio and select “New Project” from the “File” menu. Create a new class library in your favorite language. For this demo purpose, I am choosing Visual C#.

We will write a simple Calculator program which performs the basic arithmetic operations. Let us name the class library “MathLib”.

When the MathLib class library project is created, it will create a new class called “Class1.cs” by default. Let us rename this file to “Calculator.cs”. Remember to change the class name as well as file name.

Let us add the stubs for some basic arithmetic operations to our Calculator class:

namespace MathLib
{
public class Calculator
{
public int Add(int a, int b)
{
return a + b;
}

public int Subtract(int a, int b)
{
return a - b;
}

public int Multiply(int a, int b)
{
return a * b;
}

public int Divide(int a, int b)
{
return a / b;
}
}
}

Now we have a class library project with the name “MathLib” and a class in the library with the name “Calculator”. The Calculator class has the public methods to Add, Subtract, Multiply and Divide.

Build your project and make sure everything is compiling.




Previous Chapter: Test menu in Visual Studio
More Chapters: Visual Studio Team Test Tutorials
More Tutorials: Tutorial Index



Top Contributors
Today
    Last 7 Daysmore...

    Awards & Gifts

    Online Members

    srirama
    More...
     
    Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India