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:
- Equality = AreEqual, AreNotEqual
- Identity = AreSame, AreNotSame, Contains
- Condition = IsTrue, IsFalse, IsNull, IsNotNull, IsNaN, IsEmpty, IsNotEmpty
- Type = IsInstanceOf<T>, IsNotInstanceOf<T>, IsAssignableFrom<T>, ...
- Exception = Assert.Throws ..
- String = Contains, StartsWith, EndsWith, AreEqualIgnoringCase, IsMatch (regex)
- Collections = AllItemsAre ... InstanceOfType, NotUnull, Unique, Equal, ..
- File = AreEqual, AreNotEqual
- Directory = AreEqual, AreNotEqual
When you refactoring, keep in mind that name matters.