"No one is harder on a talented person than the person themselves" - Linda Wilkinson ; "Trust your guts and don't follow the herd" ; "Validate direction not destination" ;

May 21, 2011

.NET API Testing - Part II - Nunit Tests

In continuation with previous post we are now going to write Nunit Tests for earlier post.
1. Downloaded Nunit from link
2. Created a Test Project in VS 2008
3. Add Reference to DLL nunit.framework.dll in the project
4. Copy below modifed code in UnitTest1.cs

public class TestDesign
    public int SumofTwoNumbers(int InputA, int InputB)
        return (InputA + InputB);

namespace APITest
    using NUnit.Framework;

    public class TestExample
        //Test Method
        public void TestAddAPI()
            TestDesign TD = new TestDesign();
            Assert.AreEqual(30,TD.SumofTwoNumbers(10, 20));
            Assert.AreEqual(33, TD.SumofTwoNumbers(10, 23));

        //Data Driven Testing
        [TestCase(10, 10, Result=20)]
        [TestCase(15, 15, Result=30)]
        [TestCase(20, 20, Result=40)]
        public int TestAddAPI(int a, int b)
            TestDesign TD = new TestDesign();
            return TD.SumofTwoNumbers(a, b);
5. Build the Project
6. Using Nunit Open the Debug folder, You will see Test Project DLL. Below is the snapshot of results

More Reads - Nunit Quick Start
A Test Harness with WatiN, TestDriven.NET, NUnit with Visual Studio 2008 (Team System)
Getting started with NUnit and BizUnit
Automated Testing with Selenium 2 and NUnit

Happy Reading!!

No comments: