Skip to main content

GET STARTED

AI Prompts for Test Generation

Generate high-quality Karate tests using AI assistants like GitHub Copilot, Claude, and ChatGPT.These prompts are optimized for the karate-todo application.

Quick Start Prompts

Start with these simple prompts to generate your first Karate tests.

Basic API Test Structure

Generate a Karate feature file for testing a REST API with:
- Feature name and description
- Background section with base URL
- A simple GET request scenario
- Status code and response validation

Your First TODO Test

Create a Karate test that:
1. Creates a new TODO item with title "Buy groceries"
2. Verifies the response status is 201
3. Validates the returned TODO has an id
4. Checks the title matches what was sent

CRUD Operation Prompts

Master the fundamental operations with these comprehensive prompts.

Generate a Karate test for creating a TODO item via POST to /todos endpoint.
The request should include:
- title: "Complete Karate workshop"
- completed: false
- userId: 1

Validate:
- Status code 201
- Response contains generated id
- All fields match the request
- Store the id in a variable for later use

Multi-Step Flow Prompts

Build comprehensive test scenarios that mirror real user journeys.

User Journey Test

Create a complete Karate test flow for a user managing their TODO list:
1. Create a user account (if API supports it)
2. Create 3 TODO items for that user
3. Mark the first one as complete
4. Get all TODOs for the user and verify count is 3
5. Delete the completed TODO
6. Verify only 2 TODOs remain
Use variables to pass data between steps.

Data Cleanup Flow

Generate a Karate test with proper cleanup:
1. In the Background, define cleanup functions
2. Create multiple test resources
3. Store all created IDs in an array
4. In an After hook, delete all created resources
5. Include error handling for cleanup failures

Assertion-Focused Prompts

Create robust validations with these assertion patterns.

Comprehensive Response Validation

Write Karate assertions to validate a TODO response with:
- id is a number
- title is a non-empty string
- completed is a boolean
- userId exists and is positive
- Optional: createdAt matches ISO date format
- Optional: tags is an array (can be empty)
Use match with appropriate validators (#number, #string, #boolean, #present)

Array and Collection Assertions

Generate Karate tests that validate TODO lists:
1. Check array is not empty
2. Verify exact count: match response == '#[5]'
3. Validate each item structure
4. Find specific item: match response[?(@.title=='My TODO')]
5. Check all items meet criteria: match each response == {completed: false}
6. Verify unique IDs: match response[*].id == '#[]'

Negative Assertions

Create Karate assertions for error scenarios:
- Response does NOT contain sensitive data (password, token)
- Error message is present but not too detailed
- Status is not 500 (internal error)
- Response time is under 2 seconds
- Required fields are not null or empty

Data-Driven Test Prompts

Generate tests that work with multiple data sets.

Generate a Karate Scenario Outline that tests creating TODOs with different data:
- Valid titles (short, long, special characters)
- Different completed states (true, false)
- Various user IDs
Use an Examples table with at least 5 test cases.
Include both positive and edge cases.

Negative Testing Prompts

Test error conditions and edge cases effectively.

Invalid Input Testing

Generate Karate tests for invalid TODO creation:
1. Missing required title field - expect 400
2. Title is empty string - expect 400
3. Title exceeds 500 characters - expect 400
4. Invalid userId (negative, string) - expect 400
5. Malformed JSON payload - expect 400
Each test should verify appropriate error message.

Authorization Testing

Create Karate tests for authorization scenarios:
1. Access TODO without auth token - expect 401
2. Use expired token - expect 401
3. Access another user's TODO - expect 403
4. Valid token but insufficient permissions - expect 403
Include proper header configuration for auth tokens.

Advanced Pattern Prompts

Level up with sophisticated testing patterns.

Retry Logic

Generate a Karate test with retry logic:
1. Create a TODO that triggers async processing
2. Poll GET /todos/{id}/status until status is 'completed'
3. Maximum 10 retries with 2-second delays
4. Fail if not completed within timeout
5. Validate final processed result

Conditional Logic

Write a Karate test with conditional flows:
- If environment is 'prod', use read-only tests
- If environment is 'dev', include create/delete
- If a feature flag is enabled, test new endpoints
- Skip certain tests based on API version
Use karate.get() and conditional blocks.

Performance Assertions

Create a Karate test that validates performance:
1. Measure response time for creating a TODO
2. Assert it's under 500ms
3. Create 10 TODOs in parallel
4. Verify all complete within 2 seconds
5. Check no requests failed
Use responseTime and parallel features.

Best Practices Prompt

Generate well-structured, maintainable test suites.

Generate a well-organized Karate test suite for TODO API with:
1. Proper feature file organization
2. Reusable functions in separate files
3. Environment-specific configuration
4. Shared test data
5. Clear scenario names and tags
6. Comprehensive but maintainable assertions
7. Performance considerations
8. Cleanup strategies

Follow Karate best practices for maintainability.

Workshop Exercises

Practice with these hands-on exercises using the karate-todo application.

Exercise 1: Basic CRUD

Using the karate-todo app:
Create a complete CRUD test suite that:
- Tests all four operations (Create, Read, Update, Delete)
- Uses variables to pass data between operations
- Includes proper assertions for each step
- Handles cleanup

Exercise 2: Flow Testing

Build a realistic user flow test:
1. User creates a TODO list for a project
2. Adds 5 tasks to the list
3. Marks tasks as complete as they're done
4. Filters to see only incomplete tasks
5. Generates a summary of completed vs pending

Exercise 3: Error Handling

Create a negative test suite that:
- Tests all possible error conditions
- Validates error messages are helpful
- Ensures no sensitive data in error responses
- Verifies proper HTTP status codes
- Includes boundary value testing

Tips for Using These Prompts

Best Practices
  1. Start Simple: Begin with basic CRUD operations before moving to complex flows
  2. Iterate: Generate initial test, then ask AI to add more assertions
  3. Context Matters: Always specify your API structure and endpoints
  4. Review Generated Code: AI output needs verification against actual API behavior
  5. Combine Prompts: Mix and match sections for comprehensive tests

Next Steps

Ready to put these prompts into action?

  1. Open your favorite AI assistant (GitHub Copilot, Claude, ChatGPT)
  2. Copy a prompt that matches your testing needs
  3. Customize it with your API details
  4. Generate and refine your Karate tests
  5. Run tests against your API