Test-driven development
This is a model-invoked discipline. When the change is behavioral, drive it with tests.
The loop: red → green → refactor
- Red — write one failing test that describes the next small increment of behavior. Run it; confirm it fails for the right reason.
- Green — write the minimum code to make it pass. Don't gold-plate.
- Refactor — clean up names, duplication, and structure with the test as your net. Re-run; stay green.
Repeat in small steps. Each step is one behavior, not one whole feature.
Test quality rules (ArchitectOS)
- Name tests by behavior:
should throw ConflictError when email is already registered— nottest1, nottestCreate. - Mock only at boundaries — HTTP, DB, external APIs. Don't mock the unit under test.
- Cover error paths and edges, not just the happy path. Every
throwdeserves a test. - Keep tests isolated — no shared mutable state, no order dependence, no real network.
- Arrange-Act-Assert structure; one logical assertion per test.
- Test the contract, not the implementation — avoid asserting on private internals.
The test pyramid
Favor many fast unit tests, fewer integration tests, very few end-to-end tests. If you reach for an e2e test to cover logic a unit test could catch, push it down.
When fixing a bug
Write the failing regression test first (it reproduces the bug), then fix. See aos-debugging for the full diagnosis loop.
On-demand suite audit
For a full review of an existing test suite's balance, naming, isolation, and coverage,
use /aos-qa.