Unit testing is testing of each and every individual parts of the program.For eg:-The individual part is a method inside the class. Unit tests are generally done by developers.After developer finishes his unit testing , it goes to testing team for full round of testing of the application.
In order to minimize the bugs,before it gets tested by the testing team.When change request received for the existing applications. The testers will do regression testing again and again, if any changes introduced in production environment.
MsTest
NUNit
1.Arrange
2.Act
3.Assert
In Nunit, it shows more informations when the test got failed.we can define multiple tests as decorations like this,
[Test,TestCase(1,2,3)]
[TestCase(3, 8, 11)]
[TestCase(2, 3, 11)]
[TestCase(4, 2, 6)]
public void TestMethod1(int a,int b,int res)
{
int actual;
int expected = res;
Example1NUnit objtestunit = new Example1NUnit();
actual=objtestunit.Add(a, b);
NUnit.Framework.Assert.AreEqual(expected, actual);
}
It is an open source unit testing framework which can be used for testing .Net languages. Nunit can be installed in Visual studio by using Nuget packages. Let us create a sample unit testing application using NUNIT:
If you don’t install Nunit3TestAdapter then the results will not be shown in TestExplorer.
After adding in unittesting project, you will see Nunit.framework in references of the project.but you will never seen Nunit3TestAdapter, But internally it does the work for showing the TESTEXPLORER WINDOW.
The class library for Mathematical calculations is Example1NUnit class. (i.e Example1NUnitLib.dll)
Public class Example1NUnit
{
public int Add(int I,int j)
{
return i+j;
}
public int Sub(int I,int j)
{
return i-j;
}
}
Now call this Example1NUnit.dll in NUnitExampleProject.
Decorate the Nunittest class with [TestFixture] and decorate method with [Test] like this
Using example1NUnitLib;
Using Nunit.Framework;
namespace NUNITTestingEXAMPLE
[TestFixture]
public class Nunittest
{
[Test,TestCase(1,2,3)]
public void TestMethod1(int a,int b,int res)
{
int actual;
int expected = res;
Example1NUnit objtestexample= new Example1NUnit();
actual= objtestexample.Add(a,b);
Nunit.Framework.Assert.AreEqual(expected,actual);
}
}
NUNITTestingEXAMPLE project should be class library. Don’t execute the application it is not windows application or console application.
Now the test results are opened in Test Explorer.You can see Test Explorer in left side of this picture.
Open Test Explorer : Test->Windows->TestExplorer