Api Test Automation
This skill provides automated assistance for api test automation tasks.
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
Overview
This skill provides automated assistance for api test automation tasks.
This skill provides automated assistance for the described functionality.
Examples
Example usage patterns will be demonstrated in context.
1---2name: automating-api-testing-23description: Test automate API endpoint testing including request generation, validation, and comprehensive test coverage for REST and GraphQL APIs. Use when testing API contracts, validating OpenAPI specifications, or ensuring endpoint reliability. Trigger with phrases like "test the API", "generate API tests", or "validate API contracts".4license: MIT5---6# Api Test Automation
7
8This skill provides automated assistance for api test automation tasks.
9
10## Prerequisites
11
12Before using this skill, ensure you have:
13- API definition files (OpenAPI/Swagger, GraphQL schema, or endpoint documentation)
14- Base URL for the API service (development, staging, or test environment)
15- Authentication credentials or API keys if endpoints require authorization
16- Testing framework installed (Jest, Mocha, Supertest, or equivalent)
17- Network connectivity to the target API service
18
19## Instructions
20
21### Step 1: Analyze API Definition
22Examine the API structure and endpoints:
231. Use Read tool to load OpenAPI/Swagger specifications from {baseDir}/api-specs/
242. Identify all available endpoints, HTTP methods, and request/response schemas
253. Document authentication requirements and rate limiting constraints
264. Note any deprecated endpoints or breaking changes
27
28### Step 2: Generate Test Cases
29Create comprehensive test coverage:
301. Generate CRUD operation tests (Create, Read, Update, Delete)
312. Add authentication flow tests (login, token refresh, logout)
323. Include edge case tests (invalid inputs, boundary conditions, malformed requests)
334. Create contract validation tests against OpenAPI schemas
345. Add performance tests for critical endpoints
35
36### Step 3: Execute Test Suite
37Run automated API tests:
381. Use Bash(test:api-*) to execute test framework with generated test files
392. Validate HTTP status codes match expected responses (200, 201, 400, 401, 404, 500)
403. Verify response headers (Content-Type, Cache-Control, CORS headers)
414. Validate response body structure against schemas using JSON Schema validation
425. Test authentication token expiration and renewal flows
43
44### Step 4: Generate Test Report
45Document results in {baseDir}/test-reports/api/:
46- Test execution summary with pass/fail counts
47- Coverage metrics by endpoint and HTTP method
48- Failed test details with request/response payloads
49- Performance benchmarks (response times, throughput)
50- Contract violation details if schema mismatches detected
51
52## Output
53
54The skill generates structured API test artifacts:
55
56### Test Suite Files
57Generated test files organized by resource:
58- `{baseDir}/tests/api/users.test.js` - User endpoint tests
59- `{baseDir}/tests/api/products.test.js` - Product endpoint tests
60- `{baseDir}/tests/api/auth.test.js` - Authentication flow tests
61
62### Test Coverage Report
63- Endpoint coverage percentage (target: 100% for critical paths)
64- HTTP method coverage per endpoint (GET, POST, PUT, PATCH, DELETE)
65- Authentication scenario coverage (authenticated vs. unauthenticated)
66- Error condition coverage (4xx and 5xx responses)
67
68### Contract Validation Results
69- OpenAPI schema compliance status for each endpoint
70- Breaking changes detected between specification versions
71- Undocumented endpoints or parameters found in implementation
72- Response schema violations with diff details
73
74### Performance Metrics
75- Average response time per endpoint
76- 95th and 99th percentile latencies
77- Requests per second throughput measurements
78- Timeout occurrences and slow endpoint identification
79
80## Error Handling
81
82Common issues and solutions:
83
84**Connection Refused**
85- Error: Cannot connect to API service at specified base URL
86- Solution: Verify service is running using Bash(test:api-healthcheck); check network connectivity and firewall rules
87
88**Authentication Failures**
89- Error: 401 Unauthorized or 403 Forbidden on protected endpoints
90- Solution: Verify API keys are valid and not expired; ensure bearer token format is correct; check scope permissions
91
92**Schema Validation Errors**
93- Error: Response does not match OpenAPI schema definition
94- Solution: Update OpenAPI specification to match actual API behavior; file bug if API implementation is incorrect
95
96**Timeout Errors**
97- Error: Request exceeded configured timeout threshold
98- Solution: Increase timeout for slow endpoints; investigate performance issues on API server; add retry logic for transient failures
99
100## Resources
101
102### API Testing Frameworks
103- Supertest for Node.js HTTP assertion testing
104- REST-assured for Java API testing
105- Postman/Newman for collection-based API testing
106- Pact for contract testing and consumer-driven contracts
107
108### Validation Libraries
109- Ajv for JSON Schema validation
110- OpenAPI Schema Validator for spec compliance
111- Joi for Node.js schema validation
112- GraphQL Schema validation tools
113
114### Best Practices
115- Test against non-production environments to avoid data corruption
116- Use test data factories to create consistent test fixtures
117- Implement proper test isolation with database cleanup between tests
118- Version control test suites alongside API specifications
119- Run tests in CI/CD pipeline for continuous validation
120
121## Overview
122
123
124This skill provides automated assistance for api test automation tasks.
125This skill provides automated assistance for the described functionality.
126
127## Examples
128
129Example usage patterns will be demonstrated in context.