TDD & Unit Testing

Unit Testing means test a single unit. TDD uses unit testing to drive the design. Create the test first then write the code.

TDD refers to Red, Green, and Refactor.

  • Red - Create a failed test.
  • Green - Write enough to pass the test.
  • Refactor - Clean up the code.

To do the test, we need to assert the expected and actual value. We can assert for:

  1. Equality = AreEqual, AreNotEqual
  2. Identity = AreSame, AreNotSame, Contains
  3. Condition = IsTrue, IsFalse, IsNull, IsNotNull, IsNaN, IsEmpty, IsNotEmpty
  4. Type = IsInstanceOf<T>, IsNotInstanceOf<T>, IsAssignableFrom<T>, ...
  5. Exception = Assert.Throws ..
  6. String = Contains, StartsWith, EndsWith, AreEqualIgnoringCase, IsMatch (regex)
  7. Collections = AllItemsAre ... InstanceOfType, NotUnull, Unique, Equal, ..
  8. File = AreEqual, AreNotEqual
  9. Directory = AreEqual, AreNotEqual

When you refactoring, keep in mind that name matters.

results matching ""

    No results matching ""