Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 3

N-UNIT

N-unit is software used for testing Microsoft Dot Net applications. It is used for Unit test of applications (Class library and executable). N-unit application is fully written in C# language. We can use this for both GUI and console application.

Steps to create application: 1) Create application (Console or GUI) in Dot Net. 2) Write the testing function for Functions of our application, in Test Class we want to add reference to nunit.framework.dll 3) The Test class will start with TestFixture in array parenthesis.(like [TestFixture]).It should be public class. 4) Test function will start with Test in array parenthesis.(like [Test]) 5) All test function return type should be void. 6) Compile and create DLL or EXE of the application. 7) In N-Unit select the .dll file or Exe file and start test. 8) Functions with Green color is success test, Yellow mean ignored test, Red mean failed test.

Sample Program: Arithmetic class


using System; using System.Collections.Generic; using System.Text; namespace Arithmetic { public class Mathfunction {

//Memebr variables public int First_num,Second_num; //Constructor public Mathfunction(int a, int b) { this.First_num = a; this.Second_num = b; } //Function for arithmetic operation public int addition() { return First_num+Second_num; }

public int subtract() { return First_num-Second_num; } public int multipley() { return First_num * Second_num; } public double power() { return Math.Pow((double)First_num, (double)Second_num); } } }

Test Calss:
using System; using System.Collections.Generic; using System.Text; using NUnit.Framework; namespace Arithmetic { [TestFixture] public class TestClass { Mathfunction Mathobj; [Test] public void testadditon() { Mathobj = new Mathfunction(15, 15); Assert.AreEqual(30, Mathobj.addition()); } [Test] public void testsubtract() { Mathobj = new Mathfunction(15, 15); Assert.AreEqual(0, Mathobj.subtract()); }

[Test] public void testmultipley() { Mathobj = new Mathfunction(15, 15); Assert.AreEqual(225, Mathobj.multipley()); } [Test] public void testpower() { Mathobj = new Mathfunction(3, 4); Assert.AreEqual((double)81.0, Mathobj.power()); } } }

The result of above Example is success for all test function in it.

You might also like