Tutorial by Examples

[Test] public void Calculator_Add_ReturnsSumOfTwoNumbers() { Calculator calculatorUnderTest = new Calculator(); double result = calculatorUnderTest.Add(2, 3); Assert.AreEqual(5, result); }
Given this simple class, we can test that the ShaveHead method is working correctly by asserting state of the HairLength variable is set to zero after the ShaveHead method is called. public class Person { public string Name; public int HairLength; public Person(string name, in...
Sometimes it is necessary to assert when an exception is thrown. Different unit testing frameworks have different conventions for asserting that an exception was thrown, (like NUnit's Assert.Throws method). This example does not use any framework specific methods, just built in exception handling. ...

Page 1 of 1