Agent-Based API Test Generation
Overview
Keploy Enterprise supports agent-based test generation, allowing AI coding assistants (Claude Code, Cursor, Antigravity, GitHub Copilot) to generate and iterate on API tests directly in your IDE.
Instead of switching to a separate web UI, the agent:
- Generates test YAML using the Keploy test format
- Runs tests via Keploy Enterprise with structured JSON output
- Reads coverage gaps from the output and generates targeted tests
- Syncs results to the Keploy platform for team-wide visibility
The Keploy platform automatically builds and refines the API schema over time from your test runs, so providing an OpenAPI spec upfront is optional.
Prerequisites
- Keploy Enterprise installed (installation guide)
- A running API server to test against
- An OpenAPI spec (optional; the platform generates schema coverage over time)
Setup for AI Agents
To teach your AI agent the Keploy test format, add a context file to your project root. The agent reads this file and learns how to generate valid test suites.
Claude Code
Create a CLAUDE.md file in your project root with the Keploy test format reference. Claude Code automatically reads project-level markdown files. The file should document:
- The YAML test suite schema (name, description, steps)
- Available assertion types (status_code, json_equal, json_contains, etc.)
- Variable extraction and substitution rules
- The CLI commands to run and validate tests
See the Test Suite YAML Format section below for the complete schema to include.
Cursor
Create a .cursorrules file in your project root with the same test format reference.
Antigravity
Use the same test format documentation as system instructions or project context.
Workflow
1. Initialize the test directory
keploy test-gen init --dir ./keploy
This creates:
keploy/tests/example.yaml—a working example test suitekeploy/keploy-runner.yaml—a configuration reference template
2. Generate tests with your AI agent
Ask your agent to generate tests:
"Generate API tests for my user CRUD endpoints"
The agent writes YAML test files directly to keploy/tests/.
3. Run tests
keploy test-gen run --base-url http://localhost:8080 --output json
The JSON output includes pass/fail status, assertion failures, and extracted variables. The agent reads this to fix failing tests.
4. Coverage feedback loop (optional)
If you have an OpenAPI spec, add --spec for coverage analysis:
keploy test-gen run --base-url http://localhost:8080 --spec openapi.yaml --output json
The output includes a coverage section with next_steps—prioritized suggestions for uncovered endpoints. The agent reads these and generates targeted tests automatically.
Even without a spec, the Keploy platform builds schema coverage over time from your test runs. You can view this on the Keploy dashboard.