C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...







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

  • Tutorial Index



  • dotNet Slackers

    About Us    Contact Us    Privacy Policy    Terms Of Use