Overview of Nunit Testing Framework


what is the Nunit ?

If you are new to Nunit, please go through this post How to configure Nunit in Visual Studio

It is the unit test case framework based on .Net Framework. Which is widely used by .net developer to write the unit test case. It is open source and free to use by any person. You don’t have to pay any money for this tool.

why should we use Nunit framework instead of MS-UnitTest Framework ?

These are the few important point to use Nunit instead of MS-Test

1. It is matured and stable unit test case framework
2. It gives good performance as compare to MS-Test
3. It has good community support
4. It is the popular Open Source project
5. Suite attribute - can aggregate tests and execute them separately. It will be useful for large projects.
6. NUnit has frequent version updates - MS-Test has only one per VS version.
7. It takes less memory to execute the test case as compare to MS-Test.

what are the important attributes of Nunit Framework?

There are following important attributes of NUnit Framework
a> TestFixtureAttribute

>>It is used to indicate the class which contains the test method.

b> Description

>> as the name suggest, it gives the description of class or test method

using System;
  using NUnit.Framework;

  [TestFixture, Description("Fixture description here")]
  public class SomeTests
  {
    [Test, Description("Test description here")] 
    public void TestMethod()
    { /* ... */ }
  }
}

c. SetUP
>> It is generally used for declaration of object before running the unit test case.

d. TearDown : It is generally used for cleaning the object at end of the test case.

d. Test : This attribute generally keep on top of method name. It is used for writing the unit test case related code for check the expected functionality of application.

using System;
  using NUnit.Framework;

  [TestFixture]
  public class SuccessTests
  {
    [SetUp] 
    public void Init()
    { /* ... */ }

    [TearDown]
     public void Cleanup()
    { /* ... */ }

    [Test] 
    public void Add()
    { /* ...... */ }

There are so many other attribute available in Nunit. If you are looking to learn more about it. Please check the below URL

Nunit Attributes document URL

How to configure Visual Studio with Nunit Testing Framework


As we know that Nunit is testing framework which is widely used in .net community. It is open source and free to use. So in this post we will see how to configure the Nunit with Visual studio. Here i have used Visual Studio 2015.

There are the simple steps to configure the visual studio for Nunit Testing Framework.

Step 1: Open the visual studio –> Go to Tool Menu –> Extension and updates –>Select Nunit VS Templates and Nunit 3 Test Adapter

Step 2: Install the both plugin as shown below image

Step 3: Open the visual Studio and create new Test Unit Project like this

Step 4: Write some simple unit test case and click on Run All unit test as given below image.

Now no need to attach the dll into Nunit Software UI, we can run the unit test case in Visual studio Test Explorer as given above image.