tdd
TDD Workflow
Drive feature implementation from the outside in: start with what the user sees, work inward to the models and logic, writing a failing test before every piece of implementation.
If asked to implement a feature or fix a bug without tests, write the test first. Always.
Philosophy
Outside-in
Start at the outermost seam (system test) and let failures pull you inward. A system test fails because a route is missing. Adding the route fails because the controller action is missing. The controller fails because the model has no scope. At each layer, the failure tells you what to build next. This is the outside-in progression: the tests drive the design rather than the other way around.
Seams
A seam is the public boundary you test at: the interface where you observe behavior without reaching inside. Before writing tests, identify your seams:
- System test seam: the browser. Does the user see the right thing?
- Model test seam: the public method or scope. Does it return the right result?
- Request test seam: the HTTP response. Does the endpoint do the right thing?