In this article, I am going to explain the uses of unit testing and writing unit test cases in C#.
Many junior/fresher developers might be confused about who really should deal with Unit Testing. Unit test cases are written by developers. What is Unit Testing? It tests behavior of a function/method by writing another piece of code. Image 1: Unit testing Why Unit Tests?
Imagine a situation where the change requests are happening very frequently. The efforts required for regression testing will be very high and the possibility of having defects will also be high. Software Maintenance with Normal approach (Regression Testing) Image 2: Regression Testing Regression Testing is the process of testing changes to computer programs, in order to make sure that the older programming still works with the new changes. Software Maintenance with Unit Testing Image 3: Unit Tests
Software maintenance with TDD (Test Driven Development) Image 4: TDD TDD is an evolutionary approach to the development. It combines test-first development where you write a test before you write just enough production code to fulfill that test; and then, refactor the code to pass the test. Writing Unit Test cases We have two frameworks to write Unit Test cases in C#.
We have AAA pattern to write Unit Test cases: Image 5: AAA
Programming C# for Beginners