Test-Driven Development (TDD)
The Iron Law
NO PRODUCTION CODE WITHOUT A FAILING TEST FIRST
Write code before the test? Delete it. Start over.
The Cycle
- RED — Write a test that fails. Run it. Confirm it fails for the right reason.
- GREEN — Write the minimum code to make the test pass. Nothing more.
- REFACTOR — Clean up. Both test and production code. Tests must still pass.
In the Aixlarity Codebase
# Run a specific test
cargo test -p aixlarity-core test_name
# Run all tests
cargo test
# Run with output
cargo test -- --nocapture
What Counts as "Minimum Code"
- If the test expects a return value, hardcode it first. Then generalize.
- If the test expects an error, return the error. Do not add error handling for cases no test covers yet.
- Resist the urge to "finish" the function. Let the next test drive the next behavior.
When to Skip (Ask the User First)
- Throwaway prototypes that will be deleted within the session.
- Generated code (e.g., provider adapter boilerplate).
- Configuration files.