.NET/ASP.NET Interview Question - Unit Testing can be done by using Nunit?
Shivprasad Koirala
namespace NunitTest{ public class Math { public int Add(int i, int j) { int sum; sum = i + j; return sum; } }}
namespace CheckNunit{ [TestFixture] public class NunitTest { [Test]//it is called as attribute public void check() { Math obj = new Math(); int result = obj.Add(10, 20); Assert.AreEqual(30, result); } }}
Now click on run button and see the respective output. If it displays green color then everything is working fine and if it displays red color then there is something wrong in code. The following two diagram will give you an better idea.
Let inject a small defect, so that we can check how Nunit display the result. Now I change the Addition(+) sign as Multiplication(*) sign so the method fail to add values and Nunit displays Red signal like below diagram.
Visit Authors blog for more.NET and SQL Server interview questions