nunit - testing your application. nunit tool – used for test driven development lets create a...

9
NUNIT - Testing your Application

Upload: rebecca-atkinson

Post on 02-Jan-2016

217 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: NUNIT - Testing your Application. NUnit Tool – Used for Test driven development Lets create a sample banking class named account which supports operations

NUNIT - Testing your Application

Page 2: NUNIT - Testing your Application. NUnit Tool – Used for Test driven development Lets create a sample banking class named account which supports operations

NUnit Tool – Used for Test driven development

• Lets create a sample banking class named account which supports operations to deposit, withdraw or transfer funds.

• To get started, lets create a new project, and select project type as Visual C# - Class Library

• Also give the location as C:\Documents and Settings\smktb\My Documents\Visual Studio 2005\Projects -- with your respective username and give the name to the Class Library as TestNUnit

Page 3: NUNIT - Testing your Application. NUnit Tool – Used for Test driven development Lets create a sample banking class named account which supports operations

New Class Library

Page 4: NUNIT - Testing your Application. NUnit Tool – Used for Test driven development Lets create a sample banking class named account which supports operations

Rename the class name to Account.cs from Class1.cs

Page 5: NUNIT - Testing your Application. NUnit Tool – Used for Test driven development Lets create a sample banking class named account which supports operations

Add NUnit Reference by selecting your project name, right click and add reference as shown below

Page 6: NUNIT - Testing your Application. NUnit Tool – Used for Test driven development Lets create a sample banking class named account which supports operations

Add a new class “TestAccount.cs” and add the below code. Also add the namespace “using NUnit.Framework” and then build the solution

Page 7: NUNIT - Testing your Application. NUnit Tool – Used for Test driven development Lets create a sample banking class named account which supports operations

Start NUnit GUI from Programs-Applications-NUnit-Net-2.0 – NUnit GUI. Click on File-Open-Select the folder where your program is

stored, go to the bin directory and select TestNUnit.dll

Page 8: NUNIT - Testing your Application. NUnit Tool – Used for Test driven development Lets create a sample banking class named account which supports operations

Click on Run to check the output. In this case, the test case will fail, as we did not invoke destination.Deposit(amount).

Page 9: NUNIT - Testing your Application. NUnit Tool – Used for Test driven development Lets create a sample banking class named account which supports operations

In order to correct the error, lets uncomment the line in Account.cs file which says “destination.Deposit(amount)”. Important points to note is that [TestFxture] denotes that the corresponding class contains a “Test Case” and [Test] indicates that the corresponding function is a test case