unit-testing The general rules for unit testing for all languages Example of simple unit test in C#


For this example we will test the sum method of a simple calculator.

In this example we will test the application: ApplicationToTest. This one has a class called Calc. This class has a method Sum().

The method Sum() looks like this:

public void Sum(int a, int b)
    return a + b;

The unit test to test this method looks like this:

public class UnitTest1
    public void TestMethod1()
        ApplicationToTest.Calc ClassCalc = new ApplicationToTest.Calc();
        int expectedResult = 5;

        int result = ClassCalc.Sum(2,3);

        Assert.AreEqual(expectedResult, result);