Now: Tutorial for Web and Software Design > OS > Windows > OS Content
> Unit Testing in Visual Studio 2005 Team System [Bookmark it]
Unit Testing in Visual Studio 2005 Team System

Unit Testing in Visual Studio 2005 Team System

by Wei-Meng Lee
01/03/2006
Use ClickOnce to Deploy Windows Applications

Unit testing is one of the tasks that every programmer worth their salt needs to do. For example, after writing a class, you often need to write additional code to instantiate the class and test the various methods and properties defined within it. With Visual Studio 2005 Team System, you can now use the new Unit Testing feature to auto-generate the code needed to test your application.

In this article, I will show you how unit testing is performed in Visual Studio 2005 Team System. Note that you need the Microsoft Visual Studio 2005 Beta 2 Team Edition to try the example in this article.

Creating the Application

Launch Visual Studio 2005 and create a new Windows project using the Visual Basic 2005 language. Name the project UnitTesting.

Let's start by first adding a class to the project. Right-click on the project name in Solution Explorer and select Add->New Item…. Select the Class template and name it as Point.vb.

Populate the Point.vb file with the following class definition:

Public Class Point

    Private pX, pY As Integer



    '---default constructor

    Public Sub New()



    End Sub



    '---constructor with two parameters

    Public Sub New(ByVal x As Integer, ByVal y As Integer)

        pX = x

        pY = y

    End Sub



    '---sets the X coordinate

    Property x() As Integer 

        Get

            Return pX

        End Get

        Set(ByVal Value As Integer)

            pX = Value

        End Set

    End Property



    '---sets the Y coordinate

    Property y() As Integer 

        Get

            Return pY

        End Get

        Set(ByVal Value As Integer)

            pY = Value

        End Set

    End Property



    '---calculates the length between 2 points

    Public Function length(ByVal pointOne As Point) As Single

        Return Math.Sqrt(Math.Pow(pX - pointOne.x, 2) + _

               Math.Pow(pY - pointOne.y, 2))

    End Function

End Class

This class represents points on a two-dimension system, with x and y coordinates and a method to calculate the distance between two points.

Visual Studio Hacks

Related Reading

Visual Studio Hacks
Tips & Tools for Turbocharging the IDE
By JamesAvery

Table of Contents
Index

Read Online--Safari
Search this book on Safari:
 

Code Fragments only

Pages: 1, 2, 3, 4

Next Pagearrow

[1] [2] [3] [4] Next

[Bookmark][Print] [Close][To Top]
  • Prev Article-OS:

  • Next Article-OS:
  • Related Materias
    Using Data Compression in 
    Building Photo Uploaders w
    Drag and Drop Ajax Program
    Designing Small Windows Ne
    Ensuring Application Compa
    An Inside Look at Group Po
    An Inside Look at IPSec in
    Disabling USB Storage With
    Beware of Network Sniffers
    Hacking IIS6 with Metabase
    Topics
    Photoshop Tutorial
     

    Special Effect

      3D Effect
      Photoshop Articles
    Programming Tutorial
     

    C/C++ Tutorial

      Visual Basic
      C# Tutorial
    Database Tutorial
     

    MySQL Tutorial

      MS SQL Tutorial
      Oracle Tutorial
    Graphic Design Tutorial
     

    Coreldraw Tutorial

      Illustrator Tutorial
      3D Graphics Articles
    Webmaster Articles
     

    Domain Service

      Web Hosting
      Site Promotion
    Java Tutorial&Articles
     

    Java Servlets

      JavaEE Tutorial
     

    JavaBeans Tutorial

    XML Tutorial&Articles
     

    XML Style Tutorial

      AJAX Tutorial
      XML Mobile
    Flash Tutorial&Articles
     

    Flash Video

      Action Script
      Flash Articles
    OS Tutorial&Articles
     

    Linux Tutorial

      Symbian Tutorial
      MacOS Tutorial