What are unit tests?

Unit tests verify that the logic of code is working as expected. Unit testing breaks a program down into small, testable, individual units.

Why use unit tests?

For example, if we want to test a console-based application that has the following code:

namespace UTCalculator {
    public class CalculatorFeatures
    {
        public static int AddTwoNumbers(int num1, int num2)
        {
            int result = num1 - num2;
            return result; 
        } 
    }
}

Note: We have to test a method named AddTwoNumbers in the class named CalculatorFeature.

If we call this method now, it won’t provide us with the correct output.

Get hands-on with 1200+ tech skills courses.