Introduction
Every successful software development follows a lifecycle known as SDLC (Software Development Life Cycle).As per Wikipedia: "SDLC is a process followed for a software project, within a software organization. It consists of a detailed plan describing how to develop, maintain, replace and alter or enhance specific software. The life cycle defines a methodology for improving the quality of software and the overall development process."

As we are a developer we normally understand the requirements and write the code. Apart from those we also spend some time software testing. Software testing is a process of executing a program or application with the intent of finding the software bugs. It can also be described as the process of validating and verifying a software program or application or product. I have Googled and tried to find out what kind of testing a developer can do. I got lot of solutions from the internet, and the best one I found is here. So mainly a developer must have knowledge of Unit Testing.
What is Unit Testing?
Let's try to find the exact definition of the Unit.

UNIT In this IT world a unit refers to simply a smallest piece of code which takes an input ,does certain operation, and gives an output.
And testing this small piece of code is called Unit Testing. A lot of unit test frameworks are available for .Net nowadays, if we check in Visual Studio we have MSTest from Microsoft integrated in Visual Studio. Some 3rd party frameworks are:
- NUnit
- MbUnit
Out of all these Nunit is the most-used testing Framework.
What Is NUnit?
NUnit is a unit-testing framework for all .Net languages. NUnit is Open Source software and NUnit 3.0 is released under the MIT license. This framework is very easy to work with and has user friendly attributes for working. You can check the details of Nunit from here. If you want to learn what are the main differences between MsTest and Nunit I recommend you check the following Link. You can also check several other links that are available on the internet. I did a small inspection on internet and found the following result in using different Testing frameworks. As per the Slant website, this is what most people recommend on using different unit Testing frameworks.

To work with Nunit let's set up a simple console application as follows.

Write the following class in this project.
namespace DemoProject {
public class EmployeeDetails {
public int id {
get;
set;
}
public string Name {
get;
set;
}
public double salary {
get;
set;
}
public string Geneder {
get;
set;
}
}
}
Now in the class program write some conditions which need to be tested.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DemoProject {
public class Program {
public string Login(string UserId, string Password) {
if (string.IsNullOrEmpty(UserId) || string.IsNullOrEmpty(Password)) {
return "Userid or password could not be Empty.";
} else {
if (UserId == "Admin" && Password == "Admin") {
return "Welcome Admin.";
}
return "Incorrect UserId or Password.";
}
}
public List < EmployeeDetails > AllUsers() {
List < EmployeeDetails > li = new List < EmployeeDetails > ();
li.Add(new EmployeeDetails {
id = 100, Name = "Bharat", Geneder = "male", salary = 40000
});
li.Add(new EmployeeDetails {
id = 101, Name = "sunita", Geneder = "Female", salary = 50000
});
li.Add(new EmployeeDetails {
id = 103, Name = "Karan", Geneder = "male", salary = 40000
});
li.Add(new EmployeeDetails {
id = 104, Name = "Jeetu", Geneder = "male", salary = 23000
});
li.Add(new EmployeeDetails {
id = 105, Name = "Manasi", Geneder = "Female", salary = 80000
});
li.Add(new EmployeeDetails {
id = 106, Name = "Ranjit", Geneder = "male", salary = 670000
});
return li;
}
public List < EmployeeDetails > getDetails(int id) {
List < EmployeeDetails > li1 = new List < EmployeeDetails > ();
Program p = new Program();
var li = p.getUserDetails();
foreach(var x in li) {
if (x.id == id) {
li1.Add(x);
}
}
return li1;
}
static void Main(string[] args) {}
}
}
So here I have written 3 methods or we can say some requirements which we want to test by using Unit Test. So please add a new project (Class Library Type) in the Solution Explorer as follows.

The Nunit framework does not require any specific project type, but most of the time people will add a class library to separate their code from their unit tests. You need to reference the nunit.framework.dll yourself. But if you use nuget this will be done for you automatically while installing NUnit.
















NALLAPOTHULA KRISHNAPosted Jun 3, 2024, 8:49 AM
There is an error in your code
Vijendra KushwahaPosted Dec 19, 2021, 1:40 AM
Great article
Rajesh SinghPosted Jun 27, 2019, 5:07 AM
Great article.
Nagendra PanyamPosted May 16, 2019, 5:56 AM
Well explained ,am also interest to learn about reporting that report may contain how many tests are excuted how many tests are passed,howmany are failed i want to know clear report any idea regards
Carrie YarbroughPosted Sep 4, 2018, 11:47 AM
You call a test method in your program. I think var li = p.getuserdetails(); should be var li = p.AllUsers();
Pradeep singhPosted Feb 22, 2017, 7:04 AM
Great explanation.........
Prabhat MauryaPosted Feb 17, 2017, 4:00 AM
Very good and very well explained.
Joe WilsonPosted Jan 16, 2017, 5:52 AM
Thank you very much for sharing.
Jaco ZwartsPosted Jan 16, 2017, 1:56 AM
Thank you for sharing this really helpful!
Mahesh ChandPosted Jan 14, 2017, 9:24 PM
Well written and explained Debendra Dash.