Create A Microsoft Unit Test Project

Right click on the solution file click on “Test” add the Unit Test Project to your solution.

Test

Add the reference of your project to the unit test Project.

Add the reference

  1. [TestClass]  
  2. public class UnitTest1  
  3. {  
  4.     DecimalToBinary obj = null;  
  5.     Fibonacci fObj = null;  
  6.     FizzBizz fbObj = null;  
  7.     public UnitTest1()  
  8.     {  
  9.         obj = new DecimalToBinary();  
  10.         fObj = new Fibonacci();  
  11.         fbObj = new FizzBizz();  
  12.     }  
  13.     [TestMethod]  
  14.     public void FizzBizzPass()  
  15.     {  
  16.         var ExpectedResult = "Fizz";  
  17.         var originalResult = string.Empty;  
  18.         originalResult = fbObj.checkFizzBuzz(6);  
  19.         Assert.AreEqual(ExpectedResult, originalResult);  
  20.   
  21.     }  
  22.     [TestMethod]  
  23.     public void FizzBizzFail()  
  24.     {  
  25.         var ExpectedResult = "FizzBizz";  
  26.         var originalResult = string.Empty;  
  27.         originalResult = fbObj.checkFizzBuzz(6);  
  28.         Assert.AreEqual(ExpectedResult, originalResult);  
  29.   
  30.     }  
  31.     [TestMethod]  
  32.     public void DecimalToBinaryPass()  
  33.     {  
  34.         var ExpectedResult = "1000";  
  35.         var originalResult = string.Empty;  
  36.         originalResult=obj.getDecimalNumber(8);  
  37.         Assert.AreEqual(ExpectedResult, originalResult);  
  38.   
  39.     }  
  40.     [TestMethod]  
  41.     public void DecimalToBinaryFail()  
  42.     {  
  43.         var ExpectedResult = "1001";  
  44.         var originalResult = string.Empty;  
  45.         originalResult = obj.getDecimalNumber(8);  
  46.         Assert.AreEqual(ExpectedResult, originalResult);  
  47.   
  48.     }  
  49.     [TestMethod]  
  50.     public void FibonacciPass()  
  51.     {  
  52.         List<int> ExpectedResult=new List<int>();  
  53.         var result= fObj.GetFibonacci(1);  
  54.         ExpectedResult.Add(0);  
  55.         ExpectedResult.Add(1);  
  56.         ExpectedResult.Add(1);  
  57.         CollectionAssert.AreEqual(ExpectedResult, result);  
  58.     }  
  59.     [TestMethod]  
  60.     public void FibonacciFail()  
  61.     {  
  62.         List<int> ExpectedResult = new List<int>();  
  63.         var result = fObj.GetFibonacci(1);  
  64.         ExpectedResult.Add(0);  
  65.         ExpectedResult.Add(1);  
  66.         ExpectedResult.Add(1);  
  67.         ExpectedResult.Add(2);  
  68.         CollectionAssert.AreEqual(ExpectedResult, result);  
  69.     }  
  70. }  
Once the test method is executed, the result is shown below:

Fibonaccipass

 

X

Build smarter apps with Machine Learning, Bots, Cognitive Services - Start free.

Start Learning Now