Right click on the solution file click on “Test” add the Unit Test Project to your solution.
Add the reference of your project to the unit test Project.
- [TestClass]
- public class UnitTest1
- {
- DecimalToBinary obj = null;
- Fibonacci fObj = null;
- FizzBizz fbObj = null;
- public UnitTest1()
- {
- obj = new DecimalToBinary();
- fObj = new Fibonacci();
- fbObj = new FizzBizz();
- }
- [TestMethod]
- public void FizzBizzPass()
- {
- var ExpectedResult = "Fizz";
- var originalResult = string.Empty;
- originalResult = fbObj.checkFizzBuzz(6);
- Assert.AreEqual(ExpectedResult, originalResult);
-
- }
- [TestMethod]
- public void FizzBizzFail()
- {
- var ExpectedResult = "FizzBizz";
- var originalResult = string.Empty;
- originalResult = fbObj.checkFizzBuzz(6);
- Assert.AreEqual(ExpectedResult, originalResult);
-
- }
- [TestMethod]
- public void DecimalToBinaryPass()
- {
- var ExpectedResult = "1000";
- var originalResult = string.Empty;
- originalResult=obj.getDecimalNumber(8);
- Assert.AreEqual(ExpectedResult, originalResult);
-
- }
- [TestMethod]
- public void DecimalToBinaryFail()
- {
- var ExpectedResult = "1001";
- var originalResult = string.Empty;
- originalResult = obj.getDecimalNumber(8);
- Assert.AreEqual(ExpectedResult, originalResult);
-
- }
- [TestMethod]
- 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);
- }
- [TestMethod]
- 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);
- }
- }
Once the test method is executed, the result is shown below: