- Create a class library.
- Manage Nuget package and install:
- NUnit
- NUnit Test Adapter for vs2012, vs2013 and vs2015

- The reference should be added to class library,

- Create a console project in the same solution and add the reference of the project to the class library.
- In the unit test project add the below code to test the console project.
- [TestFixture]
- public class UnitTest1 {
- DecimalToBinary obj = null;
- Fibonacci fObj = null;
- FizzBizz fbObj = null;
- public UnitTest1()
- {
- obj = new DecimalToBinary();
- fObj = new Fibonacci();
- fbObj = new FizzBizz();
- }
- [Test]
- public void FizzBizzPass()
- {
- var ExpectedResult = "Fizz";
- var originalResult = string.Empty;
- originalResult = fbObj.checkFizzBuzz(6);
- Assert.AreEqual(ExpectedResult, originalResult);
- }
- [Test]
- public void FizzBizzFail()
- {
- var ExpectedResult = "FizzBizz";
- var originalResult = string.Empty;
- originalResult = fbObj.checkFizzBuzz(6);
- Assert.AreEqual(ExpectedResult, originalResult);
- }
- [Test]
- public void DecimalToBinaryPass()
- {
- var ExpectedResult = "1000";
- var originalResult = string.Empty;
- originalResult = obj.getDecimalNumber(8);
- Assert.AreEqual(ExpectedResult, originalResult);
- }
- [Test]
- public void DecimalToBinaryFail()
- {
- var ExpectedResult = "1001";
- var originalResult = string.Empty;
- originalResult = obj.getDecimalNumber(8);
- Assert.That(ExpectedResult, Is.EqualTo(originalResult));
- }
- [Test]
- public void FibonacciPass()
- {
- List < int > ExpectedResult = new List < int > ();
- var result = fObj.GetFibonacci(1);
- ExpectedResult.Add(0);
- ExpectedResult.Add(1);
- ExpectedResult.Add(1);
- CollectionAssert.AreEqual(ExpectedResult, result);
- }
- [Test]
- public void FibonacciFail()
- {
- List < int > ExpectedResult = new List < int > ();
- var result = fObj.GetFibonacci(1);
- ExpectedResult.Add(0);
- ExpectedResult.Add(1);
- ExpectedResult.Add(1);
- ExpectedResult.Add(2);
- CollectionAssert.AreEqual(ExpectedResult, result);
- }
- }
- To test the methods,


- Other ways to test
- Install NUit Download.

Run Nunit and open the test project dll.

Click on run to know the output.

Creating NUnit Test Project
In this article you will learn about Nunit test project.


Mahesh SinghPosted May 16, 2016, 8:23 PM EDT
good one
Anish AnsariPosted Nov 15, 2015, 7:38 PM EST
NIce
Santhakumar MunuswamyPosted Nov 13, 2015, 5:13 AM EST
Good one
Sibeesh VenuTOP 100Posted Nov 11, 2015, 11:05 PM EST
Nice Share
Manas MohapatraPosted Nov 11, 2015, 7:31 PM EST
Good Introduction..