Requestly uses AI to automatically generate test scripts directly. It eliminates the need to manually write JavaScript test code, making it effortless to validate API responses, assert fields, verify schemas, and catch edge cases with just a few clicks. Simply describe what you want to test using natural language, and the AI generates ready-to-run test cases for to your current API request and response.
Getting Started with AI Test Cases Generator
Step 1: Send Your API Request
The AI Test Generator needs your latest API response to analyse the payload and generate relevant tests.- Open any request in the API Client
- Click the Send button to execute the request
- Wait for the response to be received

Step 2: Open Post Request Script
Once you have a response:- Navigate to the Scripts section
- Click on the Post-response tab
- Look for the Generate Tests button and click it

Step 3: Enter Your Natural Language Instruction
Describe what you want the tests to validate using plain English. The AI understands context and will generate appropriate test cases based on your instruction and the response payload. Example Instructions:- “Generate test cases”
- “Test that status is 200 and user.email is valid”
- “Add a schema test for the user list”
- “Validate pagination fields like page, limit, and total”
- “Check that success=true and items array is not empty”
- “Ensure the response has id, name, and email fields”
- “Verify that all timestamps are valid ISO 8601 dates”
- “Test for missing required fields in the response”

Step 4: Review the Output
Once the AI finishes generating, it displays a git-style diff view showing exactly what will change in your Post-response script:- Red lines show what will be removed
- Green lines show what will be added
- No-color lines show unchanged content

Step 5: Accept, Edit or Cancel
You have three options after reviewing the generated tests: Click Accept to replace your full Post-response script with the generated tests. The new tests will be immediately available for execution. Click Edit Instruction to refine your original instruction and regenerate. This is useful if:- The generated tests are incomplete
- You want to add more validation points
- You need different assertions
What the AI Test Generator Creates
The AI Test Generator creates comprehensive test scripts using Requestly’srq.test and rq.expect APIs with Chai.js assertions.
Example Generated Tests
For a user API endpoint returning:Advanced Test Scenarios
The AI Test Generator can handle complex scenarios:Schema Validation
Instruction: “Validate the entire response structure against a schema” Generates schema validation tests that ensure the response conforms to the expected data structure.Tips for Better AI-Generated Tests
- Be Specific: Clearly state what you want to test. Instead of “test the response,” say “test that status is 200 and email is a valid email address”
- Reference Field Names: Mention specific fields you want validated. The AI understands JSON paths like “user.email” or “data.items[0].status”
- Use Examples: Phrases like “similar to POST requests” or “like production data” help the AI understand context
- Combine Multiple Concerns: You can ask for multiple validations in one instruction: “Validate status is 200, success is true, and items array is not empty”
- Iterative Refinement: Use the “Edit Instruction” feature to progressively enhance your tests
Current Limitations
- AI Test Generator currently generates Post-response scripts only
- Requires an actual API response to analyze.
- Best results when the response has a well-structured JSON format
Combining AI-Generated and Manual Tests
You don’t need to rely entirely on AI-generated tests. You can:- Start with AI: Let the AI generate basic validation tests
- Add Custom Logic: Manually add additional test cases or pre-request scripts
- Refine Iteratively: Use the Edit Instruction feature to improve generated tests over time
- Mix Approaches: Combine AI-generated assertions with custom JavaScript logic
Running and Debugging AI-Generated Tests
After accepting the AI-generated tests, you can:- Run Tests: Click the Send button again to execute the request and run all tests
- View Results: Check the test results in the Test Results panel
- Debug: Use
console.log()in the script to debug test execution - Modify: Edit the generated code directly if you need fine-grained control
Related Topics
- Writing Tests - Learn about manual test writing and all available assertion methods
- Scripts - Understand Pre-request and Post-response scripts
- Collection Runner - Run multiple requests and tests in sequence
- RQ API Reference - Full documentation of the
rqobject and its methods

