Testing Code
БесплатноБез исполняемых скриптовНе проверенWrite automated tests for features, validate functionality against acceptance criteria, and ensure code coverage. Use when writing test code, verifying…
Об этом скилле
Testing Code
Core Workflow
Test writing follows a systematic approach: determine scope, understand patterns, map to requirements, write tests, verify coverage.
1. Determine Test Scope
Read project documentation:
docs/user-stories/US-###-*.mdfor acceptance criteria to testdocs/feature-spec/F-##-*.mdfor technical requirementsdocs/api-contracts.yamlfor API specifications- Existing test files to understand patterns
Choose test types needed:
- Unit tests: Individual functions, pure logic, utilities
- Integration tests: Multiple components working together, API endpoints
- Component tests: UI components, user interactions
- E2E tests: Complete user flows, critical paths
- Contract tests: API request/response validation
- Performance tests: Load, stress, benchmark testing
2. Understand Existing Patterns
Investigate current test approach:
- Test framework (Jest, Vitest, Pytest, etc.)
- Mocking patterns and utilities
- Test data fixtures and setup/teardown
- Assertion styles
Use code-finder agents if unfamiliar with test structure.
3. Map Tests to Requirements
Convert 3-5 acceptance criteria to specific test cases across test types:
Example mapping:
## User Story: US-101 User Login
### Test Cases
1. **Unit: Authentication service**
- validateCredentials() returns true for valid email/password
- validateCredentials() returns false for invalid password
- checkAccountStatus() detects locked accounts
2. **Integration: Login endpoint**
- POST /api/login with valid creds returns 200 + token
- POST /api/login with invalid creds returns 401 + error
- POST /api/login with locked account returns 403
3. **Component: Login form**
- Submitting form calls login API
- Error message displays on 401 response
- Success redirects to /dashboard
4. **E2E: Complete login flow**
- User enters credentials → submits → sees dashboard
- User enters wrong password → sees error → retries successfully
4. Write Tests
Unit Test Structure:
describe('AuthService', () => {
describe('validateCredentials', () => {
it('returns true for valid email and password', async () => {
const result = await authService.validateCredentials(
'[email protected]',
'ValidPass123'
);
expect(result).toBe(true);
});
it('returns false for invalid password', async () => {
const result = await authService.validateCredentials(
'[email protected]',
'WrongPassword'
);
expect(result).toBe(false);
});
});
});
Integration Test Structure:
describe('POST /api/auth/login', () => {
beforeEach(async () => {
await resetTestDatabase();
await createTestUser({
email: '[email protected]',
password: 'Test123!'
});
});
it('returns 200 and token for valid credentials', async () => {
const response = await request(app)
.post('/api/auth/login')
.send({ email: '[email protected]', password: 'Test123!' });
expect(response.status).toBe(200);
expect(response.body).toHaveProperty('token');
expect(response.body.token).toMatch(/^eyJ/); // JWT format
});
it('returns 401 for invalid password', async () => {
const response = await request(app)
.post('/api/auth/login')
.send({ email: '[email protected]', password: 'WrongPassword' });
expect(response.status).toBe(401);
expect(response.body.error).toBe('Invalid credentials');
});
});
Component Test Structure:
describe('LoginForm', () => {
it('submits form with valid data', async () => {
const mockLogin = jest.fn().mockResolvedValue({ success: true });
render(<LoginForm onLogin={mockLogin} />);
await userEvent.type(screen.getByLabelText(/email/i), '[email protected]');
await userEvent.type(screen.getByLabelText(/password/i), 'Password123');
await userEvent.click(screen.getByRole('button', { name: /log in/i }));
expect(mockLogin).toHaveBeenCalledWith({
email: '[email protected]',
password: 'Password123'
});
});
it('displays error message on API failure', async () => {
const mockLogin = jest.fn().mockRejectedValue(new Error('Invalid credentials'));
render(<LoginForm onLogin={mockLogin} />);
await userEvent.type(screen.getByLabelText(/email/i), '[email protected]');
await userEvent.type(screen.getByLabelText(/password/i), 'wrong');
await userEvent.click(screen.getByRole('button', { name: /log in/i }));
expect(await screen.findByText(/invalid credentials/i)).toBeInTheDocument();
});
});
E2E Test Structure:
test('user can log in successfully', async ({ page }) => {
await page.goto('/login');
await page.fill('[name="email"]', '[email protected]');
await page.fill('[name="password"]', 'Test123!');
await page.click('button:has-text("Log In")');
await page.waitForURL('/dashboard');
Установить Testing Code в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл Testing Code?
Write automated tests for features, validate functionality against acceptance criteria, and ensure code coverage. Use when writing test code, verifying functionality, or adding test coverage to existing code.
Как установить скилл Testing Code?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл Testing Code запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
doc-coauthoring
Guide users through a structured workflow for co-authoring documentation. Use when user wants to write documentation, proposals, technical specs, decision…
от Anthropicacademy-guide
Stop and check this skill before finishing any reply to a question about how to use Claude or a Claude product — it recommends matching courses, tutorials…
от Anthropicinternal-comms
A set of resources to help me write all kinds of internal communications, using the formats that my company likes to use. Claude should use this skill…
от Anthropicskill-development
This skill should be used when the user wants to "create a skill", "add a skill to plugin", "write a new skill", "improve skill description", "organize skill…
от Anthropic