seed-forge/harness-ai-kit/devlab-srv-test-api

Claude Code and agent skill by seed-forge/harness-ai-kit

Trust tier 3
  • community
Source check pending

Checking that the SKILL.md file is still in the repository.

后端 API 测试专家技能。支持 Java(JUnit)/ Python(pytest)/ Node.js(supertest + jest)后端项目的接口测试、Mock 服务、测试数据管理。

Install

npx vskill@latest install seed-forge/harness-ai-kit/devlab-srv-test-api

SKILL.md

The same SKILL.md was published earlier as seed-forge/harness-ai-kit/devlab-srv-test-api.

Service API 测试专家技能

专注后端微服务 API 的自动化测试能力。

支持 REST/GraphQL/OpenAPI 规范的接口测试,覆盖身份认证、数据一致性、链路追踪等核心场景。


触发条件

当用户提到以下关键词时触发此 Skill:

  • "API 测试" / "接口测试" / "interface testing"
  • "OpenAPI 测试" / "Swagger 测试"
  • "微服务集成测试" / "microservice integration test"
  • "REST API 验证" / "GraphQL schema test"
  • "认证授权测试" / "authn/authz testing"

技术栈依赖

核心 CLI
bash
# Node.js 环境
npm install -D jest supertest supertest-fetch
# Python 环境(可选)
pip install pytest requests-mock
# Java 环境(可选)
mvn add dependency:rest-assured
辅助工具
bash
# Mock Server(推荐)
npm install -D msw
# 数据生成
npm install -D faker @faker-js/faker
# Schema 验证
npm install -D ajv zod

功能范围

Phase 1: API Schema 分析与测试点提取

输入:

  • OpenAPI/Swagger YAML 文档
  • (可选)现有 API 客户端代码
  • (可选)业务需求描述

输出:

  • specs/api-endpoints.md — 接口清单与测试点
  • specs/data-contracts.md — 数据模型定义
  • specs/auth-scenarios.md — 认证授权场景
Step 1.1: OpenAPI 解析算法
typescript
interface OpenAPIAnalysis {
endpoints: {
method: 'GET' | 'POST' | 'PUT' | 'DELETE';
path: string;
operationId: string;
summary: string;
parameters: Parameter[];
requestBody?: RequestBody;
responses: Response[];
security?: SecurityRequirement[];
}[];
schemas: {
[key: string]: {
type: 'object' | 'array' | 'string' | 'number' | 'boolean';
properties?: Record<string, any>;
required?: string[];
};
};
securitySchemes: {
[key: string]: {
type: 'apiKey' | 'http' | 'oauth2' | 'openIdConnect';
scheme?: string;
bearerFormat?: string;
};
};
}
Step 1.2: 测试用例生成规则
维度测试类型示例
HTTP MethodCRUD 覆盖GET/POST/PUT/DELETE
Authentication权限验证未登录/普通用户/管理员
Query Params分页过滤排序?limit=10&offset=20
Path Params边界值验证/users/{invalid-id}
Request Body必填字段验证缺失 email/password
Response Codes状态码断言200/400/401/404/500
Data Integrity一致性校验POST after GET shows new record
Step 1.3: 输出测试计划
markdown
# specs/api-endpoints.md
## POST /api/users - 创建用户
### 测试场景
1.✅ 有效数据创建成功 (201)
2.✅ 缺少必填字段返回 400
3.✅ 邮箱格式错误返回 400
4.✅ 密码强度不足返回 400
5.✅ 重复邮箱返回 409
6.✅ 未认证请求返回 401
### 请求示例

{ "email": "user@example.com", "password": "SecurePass123!", "name": "John Doe" }

### 响应示例

{ "id": "uuid-1234", "email": "user@example.com", "name": "John Doe", "status": "active", "createdAt": "2026-07-22T10:00:00Z" }


Phase 2: API 测试代码生成

输入:

  • specs/api-endpoints.md 测试计划
  • 基础测试配置模板

输出:

  • tests/api/users.spec.ts
  • tests/api/auth.spec.ts
  • tests/integration/*.spec.ts
Step 2.1: 基础配置模板
typescript
// tests/api/setup.ts
import { test as base, expect } from '@playwright/test';
import { faker } from '@faker-js/faker';
// ========================================
// Type Definitions
// ========================================
interface UserTestData {
email: string;
password: string;
name: string;
}
interface APITestFixtures {
apiRequest: (method: string, url: string, data?: any) => Promise<Response>;
authHeader: () => Promise<Record<string, string>>;
createUser: (overrides?: Partial<UserTestData>) => Promise<UserTestData>;
}
// ========================================
// Custom Fixtures
// ========================================
export const test = base.extend<APITestFixtures>({
apiRequest: async ({ request }, use) => {
const apiRequest = async (method: string, url: string, data?: any) => {
const response = await request[method.toLowerCase()](url, {
data,
headers: { 'Content-Type': 'application/json' }
});
return response;
};
await use(apiRequest);
},
authHeader: async ({ request }, use) => {
const authHeader = async () => {
// Login and get token
const loginResponse = await request.post('/api/auth/login', {
data: {
email: process.env.TEST_ADMIN_EMAIL || 'admin@test.com',
password: process.env.TEST_ADMIN_PASSWORD || 'Admin123!'
}
});
const { token } = await loginResponse.json();
return { Authorization: `Bearer ${token}` };
};
await use(authHeader);
},
createUser: async ({ request }, use) => {
const createUser = async (overrides?: Partial<UserTestData>) => {
const userData = {
email: faker.internet.email(),
password: 'TestPass123!',
name: faker.person.fullName(),
...overrides
};
const response = await request.post('/api/users', {
data: userData,
headers: { 'Content-Type': 'application/json' }
});
if (response.status() !== 201) {
throw new Error(`Failed to create user: ${await response.text()}`);
}
return userData;
};
await use(createUser);
}
});
export { expect };
Step 2.2: CRUD 测试套件
typescript
// tests/api/users.spec.ts
import { test, expect } from './setup';
import { faker } from '@faker-js/faker';
test.describe('POST /api/users', () => {
// ========================================
// Happy Path Tests
// ========================================
test('should create user with valid data', async ({ apiRequest, createUser }) => {
const userData = await createUser();
// Verify response structure
const response = await apiRequest('GET', `/api/users/${userData.email}`);
expect(response.status()).toBe(200);
const user = await response.json();
expect(user.email).toBe(userData.email);
expect(user.name).toBe(userData.name);
expect(user.status).toBe('active');
});
test('should return correct response headers', async ({ apiRequest, createUser }) => {
const userData = await createUser();
const response = await apiRequest('POST', '/api/users', userData);
expect(response.headers()['content-type']).toContain('application/json');
expect(response.headers()['location']).toContain('/api/users/');
});
// ========================================
// Required Fields Validation
// ========================================
test('should reject request missing email', async ({ apiRequest }) => {
const response = await apiRequest('POST', '/api/users', {
name: 'Test User',
password: 'Test123!'
});
expect(response.status()).toBe(400);
const error = await response.json();
expect(error.errors).toContainEqual(
expect.objectContaining({ field: 'email' })
);
});
test('should reject request missing password', async ({ apiRequest }) => {
const response = await apiRequest('POST', '/api/users', {
email: faker.internet.email(),
name: 'Test User'
});
expect(response.status()).toBe(400);
});
// ========================================
// Field Constraints Validation
// ========================================
test('should reject email with invalid format', async ({ apiRequest }) => {
const response = await apiRequest('POST', '/api/users', {
email: 'not-an-email',
password: 'Test123!',
name: 'Test User'
});
expect(response.status()).toBe(400);
});
test('should reject weak password', async ({ apiRequest }) => {
const response = await apiRequest('POST', '/api/users', {
email: faker.internet.email(),
password: '123', // Too short
name: 'Test User'
});
expect(response.status()).toBe(400);
});
// ========================================
// Idempotency Tests
// ========================================
test('should prevent duplicate creation with same email', async ({ apiRequest, createUser }) => {
const userData = await createUser();
// Second creation attempt with same email
const response = await apiRequest('POST', '/api/users', userData);
expect([400, 409]).toContain(response.status());
});
// ========================================
// Side Effect Tests
// ========================================
test('new user should be visible in GET /api/users immediately', async ({ apiRequest, createUser }) => {
const userData = await createUser();
// Verify in list
const listResponse = await apiRequest('GET', '/api/users');
const listData = await listResponse.json();
const foundUser = listData.data.find(u => u.email === userData.email);
expect(foundUser).toBeDefined();
});
});
test.describe('GET /api/users/:id', () => {
test('should return user by valid UUID', async ({ apiRequest, createUser }) => {
const userData = await createUser();
const response = await apiRequest('GET', `/api/users/${userData.email}`);
expect(response.status()).toBe(200);
const user = await response.json();
expect(user.email).toBe(userData.email);
});
test('should return 404 for non-existent user', async ({ apiRequest }) => {
const fakeId = faker.string.uuid();
const response = await apiRequest('GET', `/api/users/${fakeId}`);
expect(response.status()).toBe(404);
});
test('should exclude sensitive fields (password hash)', async ({ apiRequest, createUser }) => {
const userData = await createUser();
const response = await apiRequest('GET', `/api/users/${userData.email}`);
const user = await response.json();
expect(user).not.toHaveProperty('password');
expect(user).not.toHaveProperty('passwordHash');
});
});
Step 2.3: 认证授权测试
typescript
// tests/api/auth.spec.ts
import { test, expect } from './setup';
test.describe('Authentication & Authorization', () => {
test('should reject requests without authentication', async ({ apiRequest }) => {
const response = await apiRequest('GET', '/api/users');
expect(response.status()).toBe(401);
});
test('should allow authenticated requests', async ({ apiRequest, authHeader }) => {
const headers = await authHeader();
const response = await apiRequest('GET', '/api/users', undefined, {
headers
});
expect(response.status()).toBe(200);
});
test('should enforce role-based access control', async ({ apiRequest, authHeader }) => {
const headers = await authHeader();
// Regular user cannot access admin endpoint
const response = await apiRequest('GET', '/api/admin/users', undefined, {
headers
});
expect(response.status()).toBe(403);
});
test('should validate JWT token expiration', async ({ apiRequest }) => {
const expiredToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...'; // Expired token
const response = await apiRequest('GET', '/api/users', undefined, {
headers: { Authorization: `Bearer ${expiredToken}` }
});
expect(response.status()).toBe(401);
});
});

Phase 3: 微服务集成测试

场景:跨服务业务流程验证

typescript
// tests/integration/order-flow.spec.ts
import { test, expect } from './setup';

This is the start of the file. Read the full SKILL.md on GitHub.

Security

  • Security scanPassed, 90 of 100Pattern checks on the skill's files.
  • Model reviewPassed

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

Repository stars
25
Repository forks
2
7-day trend score
16

Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/seed-forge/harness-ai-kit/devlab-srv-test-api/badge)](https://verified-skill.com/skills/seed-forge/harness-ai-kit/devlab-srv-test-api)

Something wrong with this skill or its page? Tell us.