Introduction
NUnit is a xunit based unit-testing framework written in C# for Microsoft.Net. It comes with a testing framework assembly and a test runner for displaying the test results.
Implementation
- Download NUnit framework from here and install it.
- Add a Visual Studio Class Library Project and name it as Calculate.Test.
- Add reference to the Project that need to test.
- Add reference to NUnit framework
The Solution structure will looks like this
-
Open CalculateTest.cs file and decorate the public class with TestFixture attribute. The TextFixture attribute compiled into an assembly when we build the project.
Let’s try for a fail case
-
Run NUnit runner application from Windows Program Menu
-
Select Open Project from File menu and load the Calculate.Test.dll. The test runner will load the assembly and using reflection API’s looks for any type that has a TestFixture attribute on it. Once the test runner identifies the TestFixture class, it will create an instance of that class and executes all the methods decorated with Test attribute.
Click the Run button to see the result.
-
Modify the test case as shown below to fix the test case.
-
Run the test will give the green signal.
Thanks,
Bimal
No comments:
Post a Comment