Test Driven Development Tutorial Videos

These videos from Misko Hevery describe how we can write testable code. They also explain how the act of writing testable code improves the design.

An Introduction to Unit Testing

Comparison of different test techniques:

Attribute Scenario testing Functional/Subsystem testing Unit testing
Scope Test the system as a user. Replace the external dependencies of the subsystem with dummy entities. Test individual classes
Speed of debugging when a test fails Takes a long time to identify and fix the bug. Need to hunt for the bug in the entire system, Identifies the bug right down to the subsystem level. It takes time to identify the bug within the subsystem. Identifies the bug right down to the method level
Speed of execution Slow and time consuming Moderate Very fast
Reliability Test are flaky. Many times the tests might fail due to issues with the test environment Less flaky than scenario tests. Issues may be encountered due to dummy interface entities Tests are crisp; less chance of tests failing due to problems with the test environment
Ease of writing tests Hard Moderately difficult Easy
Volume of tests A small set of scenario tests to verify that all subsystems operate together. A larger set of tests that identify the working of a subsystem. A large set of tests. The test code almost equal in size to the production code.

Global State and Singletons Make the Code Untestable

Law of Demeter and Dependency Injection

Inheritance, Polymorphism and Testing

Psychology of Testing: Tests as Executable Specifications