C# – xUnit Test Implementation in Fibonacci Calculation – Video

Good software comes with tests. Fortunately, Visual Studio 2019 provides quite nice ways to test the software you are creating. One of these is xUnit – xunit.net. Thus, I have decided to make a video, showing how to implement xUnit in a Visual Studio project and what are the pluses, from having tests:

In the video, I am implementing the calculation of the Fibonacci sequence through 2 different methods – one with recursion (commented out in the code below) and one quickly looping through the numbers.

I have decided to use 4 tests only – 2 for the first two corner cases and 2 others:

As the tests were written before the code, they helped to make sure that the first implementation of Fibonacci in the video worked correctly. Then, when the second implementation of Fibonacci was written, two of the tests failed:

 

 

 

 

 

 

 

This is the huge bonus of having tests, because after checking it, the code was amended within minutes – adding an explicit solution for the first two cases of Fibonacci:

The GitHub code is available here.

Tagged with: , , , ,