AI Tests and Docs: From Empty Repo to Production
AI can produce a test suite or README in minutes, but useful output requires more than asking a model to “write tests.” The reliable workflow is to give the model executable context, define what correctness means, run the result locally, and review every assumption before it reaches production. This walkthrough shows how to move from an empty repository to tested code and maintainable documentation.
1. Prepare the Repository
Start with a small, explicit task. Create the project, install its test framework, and make sure the current code runs before involving AI. For example, a JavaScript project might use npm init -y, install Vitest, and add a test script such as npm test. A Python project could use pytest and a matching command in its development requirements.
Give the model the files that define behavior: source modules, types, configuration, existing tests, and relevant package metadata. Do not paste secrets, production credentials, or an entire unrelated monorepo. A focused context produces fewer invented assumptions and lowers token usage.
2. Ask for Tests by Behavior
Describe observable behavior instead of requesting generic coverage. A strong prompt names the function, valid inputs, invalid inputs, expected output, side effects, and error handling. Ask the AI to list its test cases before writing files. This exposes missing requirements early.
For example, specify that a payment retry function should retry temporary network failures twice, stop immediately on an authorization error, preserve the original error, and avoid charging twice. Request unit tests for each case, plus a short note identifying anything that cannot be inferred from the code.
Use a fast, inexpensive model for repetitive test scaffolding, such as Claude Haiku or an appropriate GPT model. Use Claude Sonnet or Opus for difficult stateful logic, unfamiliar code, or review of subtle edge cases. 59API provides pay-as-you-go access to Claude Opus, Sonnet, Haiku, Fable, and GPT models through https://api.59api.com. It is compatible with Claude Code, Codex, and OpenAI SDK-based tools, so you can keep the same workflow while choosing a lower-cost relay with native official-quality models.
3. Run and Challenge the Output
Run the generated tests immediately. A passing test is not automatically a valuable test: it may assert the wrong result, mock the implementation instead of the dependency, or never exercise the failure path.
- Read each assertion and confirm that it checks a user-visible contract.
- Replace fixed timestamps, random values, and network calls with controlled fixtures.
- Check that tests fail when the intended behavior is deliberately broken.
- Run coverage, but investigate untested branches rather than chasing a percentage.
- Ask the model to find weak assertions, duplicated cases, and missing boundary conditions.
For API clients, test timeouts, malformed responses, rate limits, authentication failures, and retry behavior. For parsers, include empty input, unexpected tokens, Unicode, and very large input. For security-sensitive code, add tests for authorization boundaries and never use real credentials in fixtures.
4. Generate Documentation from the Same Contract
Once the behavior is verified, ask AI to document what the code actually does. Generate a concise README section covering installation, configuration, one minimal example, common errors, and the supported runtime versions. For public functions, request documentation with parameters, return values, exceptions, side effects, and a working example.
Tell the model to cite source locations or mark uncertain statements for review. This prevents polished but inaccurate claims. Have it compare the documentation against the tests: every documented example should be executable, and every important documented error should have a corresponding test.
5. Add AI to the Production Workflow
Commit tests and documentation alongside the feature they describe. In CI, run the normal formatter, type checker, test suite, coverage threshold, and documentation checks. AI should propose changes through a pull request; it should not silently edit production code or merge its own output.
Control cost by sending only changed files, caching stable project instructions, and reserving larger models for review. With 59API's low-cost pay-as-you-go access and referral rebate, it is practical to use AI repeatedly during development without committing to a large fixed subscription. You can sign up at 59API when you are ready to connect Claude Code, Codex, or an OpenAI-compatible tool.
The production standard is simple: tests must demonstrate behavior, documentation must match verified behavior, and a human must approve both. AI accelerates the writing; your test runner, code review, and CI pipeline decide whether the result ships.
Pronto para começar?
Conecte Claude e GPT em minutos pelos menores preços, sem cortes. Cadastre-se e obtenha sua chave API.
Cadastro grátis