Test-driven development (TDD) defines what working software must do before the code exists. Write a failing test, implement enough behavior to make it pass, and let the next test pull the next piece of work into scope. This catches misunderstandings earlier than writing code first and testing whatever was built. section 4.1.2
A practical test-first loop:
- State an observable requirement as a test and confirm it fails. section 3.2.1
- Implement the behavior the test demands, without adding speculative branches. section 4.1.2
- Keep unit tests quick, focused on correctness, and stable through refactoring. Tests that police internal calls or run slowly can create waste instead of preventing it. section 5.2
Listing 3.2 Failing Tests
describe('GET /orders/:id', () => {
it('should return 200 with order details for valid ID', async () => {
const response = await request(app).get('/orders/123');
expect(response.status).toBe(200);
expect(response.body).toHaveProperty('id');
});
it('should return 404 when order does not exist', async () => {
const response = await request(app).get('/orders/nonexistent');
expect(response.status).toBe(404);
});
});
These API tests expect 200 with order details for an existing ID and 404 for a missing one. Both fail against a temporary handler that returns 501; neither dictates how order retrieval must be implemented. section 3.2.1
Constrain a shipping calculation
Before implementing shipping rules, assert that a 3 kg domestic package costs 5.99. That test fixes one required outcome without first inventing zones, discounts, or extra edge cases. Add further behavior when a requirement calls for it. section 5.2
AI can scaffold tests from a contract or generate code to make an existing test pass; it need not decide what correctness means. TDD gives developers executable checks, regression protection, and confidence to refactor, but developer-readable tests may not explain business value to non-technical stakeholders. Behavior-driven development addresses that different communication problem with human-readable scenarios. The useful question is not whether every change needs a ritual, but whether the test expresses the behavior worth building. section 3.2.1 section 4.1.2 section 5.2






















