Adding tests to existing specs
In this tutorial we'll help you add tests to an existing spec.
After creating a spec and building the code, you can build out a test suite by introducing @test
links into your spec.
This can be a good workflow when you're keen to get some working code to play with as quickly as possible, and then you want to firm it up after to make it easier to make changes in future without regressing the behavior.
In this example we start with a spec for a spaced repetition algorithm. There are no tests, just detailed requirements that describe the expected behaviour:
Add test links to the spec
But now we decide we want to add in test cases. To do this we will simply edit the spec and prompt to include test links. In this example we'll ask this in an open ended way, but we could extend the prompt to ask only for certain behaviors to be tested - for example, we may not want to trigger tests that will need very complex mocking to verify.
Ask your agent to add test links.
Lets add test links to the spec
This should trigger the agent to use the edit spec
MCP tool, and ask for test links to be added. The agent may choose to make a detailed prompt or it may just ask for test links.

The updated spec now includes @test
links next to requirements. These point to the files that will contain the tests once generated.
Last updated