| name | tdd |
| description | Follow maina's test-driven development cycle from generated stubs through red-green-refactor. |
| triggers | ["write tests","test driven","tdd","test first","generate test stubs"] |
Test-Driven Development
When to use
When implementing any feature or fixing any bug. Maina enforces TDD as the default development practice: tests are written before implementation, and the plan analysis checks that test tasks precede implementation tasks.
Steps
- Generate test stubs with
maina spec (or call the suggestTests MCP tool). This reads the current feature's plan.md and creates test files for each task, organized by test category.
- Five test categories are generated for comprehensive coverage:
- Happy path: The expected behavior works correctly with valid inputs.
- Edge cases: Boundary values, empty inputs, maximum sizes, concurrent access.
- Error handling: Invalid inputs return proper Result errors, not thrown exceptions.
- Security: Authentication required, authorization enforced, inputs sanitized.
- Integration: Components work together correctly across module boundaries.
- Red phase: All generated stubs contain a deliberately failing assertion. Run the project's test runner and confirm every stub fails. If a stub passes, the test is not actually testing anything -- fix it.
- Green phase: For each failing test, write the minimal implementation code needed to make it pass. Do not add features beyond what the test requires. Run the test runner after each change.
- Refactor phase: Once all tests pass, clean up the implementation:
- Extract duplicated logic into shared functions.
- Improve naming and structure.
- Run the test runner after each refactor to ensure tests stay green.
- Verify the cycle with
maina verify (or call the verify MCP tool) to confirm all deterministic checks pass on your changes.
Example
maina spec
maina verify
Notes
- Use the test runner configured for your project. Maina auto-detects it from your project configuration.
- The
maina analyze command checks that test tasks (T001: Write tests for X) appear before their implementation tasks (T002: Implement X) in the plan.
- Run a subset of tests during development by filtering on the test name or file path.
- Error handling tests should verify the
Result<T, E> pattern: check result.ok is false and result.error contains the expected message.
- All commands are available as both CLI (
maina <command>) and MCP tools when running inside an AI coding tool.