api-test-automation
Automated API endpoint testing with request generation, validation, and comprehensive test coverage
View on GitHubTable of content
Automated API endpoint testing with request generation, validation, and comprehensive test coverage
Installation
npx claude-plugins install @jeremylongshore/claude-code-plugins-plus/api-test-automation
Contents
Folders: agents, skills
Files: LICENSE, README.md
Documentation
Automated API endpoint testing with intelligent test generation, validation, and comprehensive coverage for REST and GraphQL APIs.
Features
- REST API testing - Complete CRUD operation coverage
- GraphQL testing - Queries, mutations, subscriptions
- Authentication - Multiple auth methods (Bearer, OAuth, API keys)
- Contract testing - Validate against OpenAPI/Swagger specs
- Automatic test generation - Analyze endpoints and generate tests
- Comprehensive validation - Status codes, headers, body structure
- Performance testing - Response time assertions
- Security testing - Auth bypass, injection attempts
Installation
/plugin install api-test-automation@claude-code-plugins-plus
Usage
The API testing agent activates automatically when you mention API testing needs. You can also invoke directly:
Generate tests for REST API
Generate API tests for the user management endpoints in src/routes/users.js
Test GraphQL API
Create GraphQL API tests for the product queries and mutations
Validate against OpenAPI spec
Generate contract tests validating against openapi.yaml
Test authentication flows
Create tests for JWT authentication including login, refresh, and protected endpoints
What Gets Generated
1. Complete Test Suites
// RESTful API test example
describe('User API', () => {
// Authentication tests
describe('POST /api/auth/login', () => {
it('should return JWT token with valid credentials', async () => {
const response = await api.post('/api/auth/login', {
email: '[email protected]',
password: 'password123'
});
expect(response.status).toBe(200);
expect(response.data).toHaveProperty('token');
expect(response.data).toHaveProperty('user');
expect(response.data.user.email).toBe('[email protected]');
});
it('should return 401 with invalid credentials', async () => {
const response = await api.post('/api/auth/login', {
email: '[email protected]',
password: 'wrongpassword'
});
expect(response.status).toBe(401);
expect(response.data.error).toBe('Invalid credentials');
});
});
// CRUD operations
describe('GET /api/users', () => {
it('should require authentication', async () => {
const response = await api.get('/api/users');
expect(response.status).toBe(401);
});
it('should return user list with valid token', async () => {
const response = await api.get('/api/users', {
headers: { Authorization: `Bearer ${authToken}` }
});
expect(response.status).toBe(200);
expect(Array.isArray(response.data)).toBe(true);
expect(response.data[0]).toHaveProperty('id');
expect(response.data[0]).toHaveProperty('email');
});
});
describe('POST /api/users', () => {
it('should create user with valid data', async () => {
const newUser = {
email: '[email protected]',
name: 'John Doe',
role: 'user'
};
const response = await api.post('/api/users', newUser, {
headers: { Authorization: `Bearer ${adminToken}` }
});
expect(response.status).toBe(201);
expect(response.data.email).toBe(newUser.email);
expect(response.data).toHaveProperty('id');
});
it('should validate required fields', async () => {
const response = await api.post('/api/users', {}, {
headers: { Authorization: `Bearer ${adminToken}` }
});
expect(response.status).toBe(400);
expect(response.data.errors).toContain('email');
});
});
});
2. Authentication Helpers
// Authentication utility functions
async function loginUser(email, password) {
const response = await api.post('/api/auth/login', { email, password });
return response.data.token;
}
async function createTestUser(role = 'user') {
const user = {
email: `test-${Date.now()}@example.com`,
password: 'test123',
role
};
await api.post('/api/users', user, { headers: { Authorization: adminToken } });
return loginUser(user.email, user.password);
}
3. Test Data Factories
// Factory functions for test data
const userFactory = {
valid: () => ({
email: `user-${Date.now()}@example.com`,
name: 'Test User',
password: 'securePassword123'
}),
invalid: () => ({
email: 'invalid-email',
name: '',
password: '123' // Too short
})
};
4. GraphQL Tests
describe('GraphQL API', () => {
describe('Query: user', () => {
it('should fetch user by ID', async () => {
const query = `
query GetUser($id: ID!) {
user(id: $id) {
id
email
name
}
}
`;
const response = await graphql.query(query, { id: userId });
expect(response.errors).toBeUndefined();
expect(response.data.user.id).toBe(us
...(truncated)
## Included Skills
This plugin includes 1 skill definition:
### automating-api-testing
> |
<details>
<summary>View skill definition</summary>
# 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:
1. Use Read tool to load OpenAPI/Swagger specifications from {baseDir}/api-specs/
2. Identify all available endpoints, HTTP methods, and request/response schemas
3. Document authentication requirements and rate limiting constraints
4. Note any deprecated endpoints or breaking changes
### Step 2: Generate Test Cases
Create comprehensive test coverage:
1. Generate CRUD operation tests (Create, Read, Update, Delete)
2. Add authentication flow tests (login, token refresh, logout)
3. Include edge case tests (invalid inputs, boundary conditions, malformed requests)
4. Create contract validation tests against OpenAPI schemas
5. Add performance tests for critical endpoints
### Step 3: Execute Test Suite
Run automated API tests:
1. Use Bash(test:api-*) to execute test framework with generated test files
2. Validate HTTP status codes match expected responses (200, 201, 400, 401, 404, 500)
3.
...(truncated)
</details>
## Source
[View on GitHub](https://github.com/jeremylongshore/claude-code-plugins-plus-skills)