SuperAPI AI Directory

tdd

Testing & quality

View repository

Updated 10-15 21:08

About this skill

TDD (Test-Driven Development)

Turn a specification into fully functional code verified by tests. Starting from an agent brief or a PRD, loop through "red → green → refactor", pausing at the end of each loop to wait for user review.

Prerequisites

A specification (an agent brief from /triage or a PRD from /to-prd ).

Process

1. Scoping

Read the specification. Read CONTEXT.md and the ADRs related to the modules you will be touching.

Read custom instructions. In tests.md , users can define their own testing rules—preferred frameworks, patterns, naming conventions, etc.

Choose a slice. Break the specification into independently testable behavior slices. The first slice should be the smallest, most valuable end-to-end behavior. Subsequent slices can start by extending that behavior or introducing new behavior.

2. Red

Write a failing test. Write the test using the patterns in tests.md , and explicitly reference that specification—follow the principles in interface-design.md . Strive to test through real interfaces rather than mocks, unless a method genuinely has side effects (see mocking.md)。

Run the test. Make sure the test is independent and fast to run. Make it __ fail __. Check whether the failure reason matches what you expected. Paste the failure output to the user.

Pause. Get the user's consent before continuing:

Test written: <测试名称>
Expected: <预期行为>
Actual: <实际失败原因>
Continue? (y/n/change spec)

3. Green

Implement the minimum code. Write only enough implementation to pass the test—the goal is to make the test green, not to make it perfect. [TODO] comments are allowed, but the fewer the better.

Check for regressions. See whether the interface you added is deep or shallow (see deep-modules.md), and whether your implementation introduces architectural regression. If you find points of regression, note them down, but you do not have to fix them in this step.

Run the test. Paste the passing (or failing) output along with an implementation summary for review.

Pause。

Implemented: <简要说明>
Passing: <测试名称>
Not yet: <尚未实现的切片>
Check: <任何潜在的倒退,附建议>
Continue? (y/n/refactor)

4. Refactor

Look for refactoring points. Review your implementation and the surrounding code. Apply the checklist in refactoring.md . Focus on eliminating duplication and deepening shallow modules.

If there are suitable refactoring points, implement them step by step, running tests as you go. If there are none, state explicitly why.

Refactored: <简要说明> 或无
Continue? (y/n/next slice)

5. Loop

Return to step 2 (red) and handle the next behavior slice. Pause after each test to stay in control of the code. Continue until all behaviors covered by the specification have been implemented and pass their tests. If you discover during the process that the specification itself has problems, stop and discuss with the maintainer.