May 19, 2014

MVC Unit Testing

http://www.codeproject.com/Articles/763928/MVC-Unit-Testing-Unleashed#BasicexampleofUnitTesting
http://www.codeproject.com/Articles/763928/MVC-Unit-Testing-Unleashed




namespace MyMathsLibrary
{
    public class CustomMaths
    {
        public int Number1 { get; set; }
        public int Number2 { get; set; }

        public CustomMaths(int num1, int num2)
        {
            Number1 = num1;
            Number2 = num2;
        }
        public int Add()
        {
            return Number1 + Number2;
        }      
    }
}


**********************UnitTest****************
namespace MathsTest
{
[TestClass]
public class TestMathsClass
{
    [TestMethod]
    public void TestAdd()
    {
        //Arrange
        CustomMaths maths = new CustomMaths(6, 5);

        //Act
        int result = maths.Add();

        //Assert
        Assert.AreEqual<int>(11, result);
    }
}
}

No comments:

Post a Comment