Prerequisites
Before using this skill, ensure you have:
- API definition files (OpenAPI/Swagger, GraphQL schema, or endpoint documentation)
- Base URL for the API service (development, staging, or test environment)
- Authentication credentials or API keys if endpoints require authorization
- Testing framework installed (Jest, Mocha, Supertest, or equivalent)
- Network connectivity to the target API service
Instructions
Step 1: Analyze API Definition
Examine the API structure and endpoints:
- Use Read tool to load OpenAPI/Swagger specifications from {baseDir}/api-specs/
- Identify all available endpoints, HTTP methods, and request/response schemas
- Document authentication requirements and rate limiting constraints
- Note any deprecated endpoints or breaking changes
Step 2: Generate Test Cases
Create comprehensive test coverage:
- Generate CRUD operation tests (Create, Read, Update, Delete)
- Add authentication flow tests (login, token refresh, logout)
- Include edge case tests (invalid inputs, boundary conditions, malformed requests)
- Create contract validation tests against OpenAPI schemas
- Add performance tests for critical endpoints
Step 3: Execute Test Suite
Run automated API tests:
- Use Bash(test:api-*) to execute test framework with generated test files
- Validate HTTP status codes match expected responses (200, 201, 400, 401, 404, 500)
- Verify response headers (Content-Type, Cache-Control, CORS headers)
- Validate response body structure against schemas using JSON Schema validation
- Test authentication token expiration and renewal flows
Step 4: Generate Test Report
Document results in {baseDir}/test-reports/api/:
- Test execution summary with pass/fail counts
- Coverage metrics by endpoint and HTTP method
- Failed test details with request/response payloads
- Performance benchmarks (response times, throughput)
- Contract violation details if schema mismatches detected
Output
The skill generates structured API test artifacts:
Test Suite Files
Generated test files organized by resource:
{baseDir}/tests/api/users.test.js - User endpoint tests
{baseDir}/tests/api/products.test.js - Product endpoint tests
{baseDir}/tests/api/auth.test.js - Authentication flow tests
Test Coverage Report
- Endpoint coverage percentage (target: 100% for critical paths)
- HTTP method coverage per endpoint (GET, POST, PUT, PATCH, DELETE)
- Authentication scenario coverage (authenticated vs. unauthenticated)
- Error condition coverage (4xx and 5xx responses)
Contract Validation Results
- OpenAPI schema compliance status for each endpoint
- Breaking changes detected between specification versions
- Undocumented endpoints or parameters found in implementation
- Response schema violations with diff details
Performance Metrics
- Average response time per endpoint
- 95th and 99th percentile latencies
- Requests per second throughput measurements
- Timeout occurrences and slow endpoint identification
Error Handling
Common issues and solutions:
Connection Refused
- Error: Cannot connect to API service at specified base URL
- Solution: Verify service is running using Bash(test:api-healthcheck); check network connectivity and firewall rules
Authentication Failures
- Error: 401 Unauthorized or 403 Forbidden on protected endpoints
- Solution: Verify API keys are valid and not expired; ensure bearer token format is correct; check scope permissions
Schema Validation Errors
- Error: Response does not match OpenAPI schema definition
- Solution: Update OpenAPI specification to match actual API behavior; file bug if API implementation is incorrect
Timeout Errors
- Error: Request exceeded configured timeout threshold
- Solution: Increase timeout for slow endpoints; investigate performance issues on API server; add retry logic for transient failures
Resources
API Testing Frameworks
- Supertest for Node.js HTTP assertion testing
- REST-assured for Java API testing
- Postman/Newman for collection-based API testing
- Pact for contract testing and consumer-driven contracts
Validation Libraries
- Ajv for JSON Schema validation
- OpenAPI Schema Validator for spec compliance
- Joi for Node.js schema validation
- GraphQL Schema validation tools
Best Practices
- Test against non-production environments to avoid data corruption
- Use test data factories to create consistent test fixtures
- Implement proper test isolation with database cleanup between tests
- Version control test suites alongside API specifications
- Run tests in CI/CD pipeline for continuous validation
1---2name: automating-api-testing3version: 1.0.04description: |5 Automate API endpoint testing including request generation, validation, and comprehensive test coverage for REST and GraphQL APIs.6 Use when testing API contracts, validating OpenAPI specifications, or ensuring endpoint reliability.7 Trigger with phrases like "test the API", "generate API tests", or "validate API contracts".8allowed-tools: Read, Write, Edit, Grep, Glob, Bash(test:api-*)9license: MIT10---1112## Prerequisites1314Before using this skill, ensure you have:15- API definition files (OpenAPI/Swagger, GraphQL schema, or endpoint documentation)16- Base URL for the API service (development, staging, or test environment)17- Authentication credentials or API keys if endpoints require authorization18- Testing framework installed (Jest, Mocha, Supertest, or equivalent)19- Network connectivity to the target API service2021## Instructions2223### Step 1: Analyze API Definition24Examine the API structure and endpoints:251. Use Read tool to load OpenAPI/Swagger specifications from {baseDir}/api-specs/262. Identify all available endpoints, HTTP methods, and request/response schemas273. Document authentication requirements and rate limiting constraints284. Note any deprecated endpoints or breaking changes2930### Step 2: Generate Test Cases31Create comprehensive test coverage:321. Generate CRUD operation tests (Create, Read, Update, Delete)332. Add authentication flow tests (login, token refresh, logout)343. Include edge case tests (invalid inputs, boundary conditions, malformed requests)354. Create contract validation tests against OpenAPI schemas365. Add performance tests for critical endpoints3738### Step 3: Execute Test Suite39Run automated API tests:401. Use Bash(test:api-*) to execute test framework with generated test files412. Validate HTTP status codes match expected responses (200, 201, 400, 401, 404, 500)423. Verify response headers (Content-Type, Cache-Control, CORS headers)434. Validate response body structure against schemas using JSON Schema validation445. Test authentication token expiration and renewal flows4546### Step 4: Generate Test Report47Document results in {baseDir}/test-reports/api/:48- Test execution summary with pass/fail counts49- Coverage metrics by endpoint and HTTP method50- Failed test details with request/response payloads51- Performance benchmarks (response times, throughput)52- Contract violation details if schema mismatches detected5354## Output5556The skill generates structured API test artifacts:5758### Test Suite Files59Generated test files organized by resource:60- `{baseDir}/tests/api/users.test.js` - User endpoint tests61- `{baseDir}/tests/api/products.test.js` - Product endpoint tests62- `{baseDir}/tests/api/auth.test.js` - Authentication flow tests6364### Test Coverage Report65- Endpoint coverage percentage (target: 100% for critical paths)66- HTTP method coverage per endpoint (GET, POST, PUT, PATCH, DELETE)67- Authentication scenario coverage (authenticated vs. unauthenticated)68- Error condition coverage (4xx and 5xx responses)6970### Contract Validation Results71- OpenAPI schema compliance status for each endpoint72- Breaking changes detected between specification versions73- Undocumented endpoints or parameters found in implementation74- Response schema violations with diff details7576### Performance Metrics77- Average response time per endpoint78- 95th and 99th percentile latencies79- Requests per second throughput measurements80- Timeout occurrences and slow endpoint identification8182## Error Handling8384Common issues and solutions:8586**Connection Refused**87- Error: Cannot connect to API service at specified base URL88- Solution: Verify service is running using Bash(test:api-healthcheck); check network connectivity and firewall rules8990**Authentication Failures**91- Error: 401 Unauthorized or 403 Forbidden on protected endpoints92- Solution: Verify API keys are valid and not expired; ensure bearer token format is correct; check scope permissions9394**Schema Validation Errors**95- Error: Response does not match OpenAPI schema definition96- Solution: Update OpenAPI specification to match actual API behavior; file bug if API implementation is incorrect9798**Timeout Errors**99- Error: Request exceeded configured timeout threshold100- Solution: Increase timeout for slow endpoints; investigate performance issues on API server; add retry logic for transient failures101102## Resources103104### API Testing Frameworks105- Supertest for Node.js HTTP assertion testing106- REST-assured for Java API testing107- Postman/Newman for collection-based API testing108- Pact for contract testing and consumer-driven contracts109110### Validation Libraries111- Ajv for JSON Schema validation112- OpenAPI Schema Validator for spec compliance113- Joi for Node.js schema validation114- GraphQL Schema validation tools115116### Best Practices117- Test against non-production environments to avoid data corruption118- Use test data factories to create consistent test fixtures119- Implement proper test isolation with database cleanup between tests120- Version control test suites alongside API specifications121- Run tests in CI/CD pipeline for continuous validation