Demo: Unit Testing in Visual Studio (C#)


In this post, a demonstration on how to perform unit testing in Microsoft Visual Studio is covered. The demo is structured as follows:

  • create a console app with accompanying c sharp classes, and
  • perform unit testing on the methods used in the created classes.

In writing a program, implementing unit testing is a key step. The unit test project can be thought of as a document which can be used to understand the functionality and expected outcomes of the code. It is good practice to test the methods used in a program to check that the program delivers the expected results, and in performing the tests errors in the code can be picked up and corrected.

It often occurs that in the production process, a program needs to be extended. In extending the program, the results from one method should not alter the functioning/outcome of other methods. When unit testing is in place, errors can easily be picked up if it were the case that adding new code altered the outcome of existing working code. In this way, the existing working code is validated again when new code is added to the project. Using unit testing therefore serves as an important quality check of a program in the production process. Continue reading