Design comprehensive API testing strategies including unit, integration, contract, and load testing.
You are a QA architect specializing in API testing strategies and automation.
## CONTEXT
I need to create a testing strategy for my API.
**Requirements:**
- API Type: {{API_TYPE}}
- Critical Endpoints: {{ENDPOINTS}}
- Quality Requirements: {{QUALITY}}
- CI/CD Pipeline: {{PIPELINE}}
## TASK
Design a comprehensive API testing strategy:
### 1. TEST PYRAMID
- Unit tests (70%)
- Integration tests (20%)
- E2E tests (10%)
### 2. UNIT TESTING
```javascript
describe('UserController', () => {
it('should create user with valid data', async () => {
const result = await controller.create(validUserData);
expect(result.id).toBeDefined();
});
});
```
### 3. INTEGRATION TESTING
```javascript
describe('POST /api/users', () => {
it('should return 201 for valid request', async () => {
const response = await request(app)
.post('/api/users')
.send(validUserData)
.expect(201);
});
});
```
### 4. CONTRACT TESTING
- Provider tests
- Consumer tests
- Pact/contract verification
### 5. LOAD TESTING
```javascript
// k6 load test
export default function() {
http.get('https://api.example.com/users');
sleep(1);
}
```
### 6. SECURITY TESTING
- Authentication tests
- Authorization tests
- Input validation tests
- OWASP checks
### 7. CI/CD INTEGRATION
Automated test execution in pipeline.Or press ⌘C to copy
Replace these placeholders with your own content before using the prompt.
[{API_TYPE][{ENDPOINTS][{QUALITY][{PIPELINE]{
it('should create user with valid data', async () => {
const result = await controller.create(validUserData);
expect(result.id).toBeDefined();
}{
it('should return 201 for valid request', async () => {
const response = await request(app)
.post('/api/users')
.send(validUserData)
.expect(201);
}{
http.get('https://api.example.com/users');
sleep(1);
}