testing
БесплатноБез исполняемых скриптовНе проверенWrite and run tests including unit tests, integration tests, and E2E tests. Use when ensuring code quality, writing test cases, or setting up testing…
от Sir-chawakorn★ 32 звезды на GitHubОб этом скилле
🧪 Testing Skill
Test Types
| Type | Purpose | Tools |
|---|---|---|
| Unit | Test functions in isolation | Jest, Vitest, pytest |
| Integration | Test modules together | Supertest, pytest |
| E2E | Test full user flows | Playwright, Cypress |
Unit Test Patterns
JavaScript/TypeScript (Jest/Vitest)
describe('calculateTotal', () => {
it('should add tax correctly', () => {
expect(calculateTotal(100, 0.07)).toBe(107);
});
it('should handle zero price', () => {
expect(calculateTotal(0, 0.07)).toBe(0);
});
it('should throw on negative price', () => {
expect(() => calculateTotal(-10, 0.07)).toThrow();
});
});
Python (pytest)
def test_calculate_total():
assert calculate_total(100, 0.07) == 107
def test_calculate_total_zero():
assert calculate_total(0, 0.07) == 0
def test_calculate_total_negative():
with pytest.raises(ValueError):
calculate_total(-10, 0.07)
Test Structure (AAA Pattern)
test('should upload file successfully', async () => {
// Arrange
const file = createMockFile('video.mp4');
const uploader = new Uploader();
// Act
const result = await uploader.upload(file);
// Assert
expect(result.success).toBe(true);
expect(result.url).toContain('uploaded');
});
Mocking
// Mock function
const mockFetch = jest.fn().mockResolvedValue({ ok: true });
// Mock module
jest.mock('./api', () => ({
fetchData: jest.fn().mockResolvedValue({ data: [] })
}));
// Mock timer
jest.useFakeTimers();
jest.advanceTimersByTime(3000);
E2E Testing (Playwright)
test('upload flow', async ({ page }) => {
await page.goto('https://tiktok.com/upload');
// Upload file
await page.setInputFiles('input[type="file"]', 'video.mp4');
// Fill form
await page.fill('[placeholder="Title"]', 'My Video');
// Submit
await page.click('button:has-text("Post")');
// Verify
await expect(page.locator('.success')).toBeVisible();
});
Test Checklist
- Happy path covered
- Edge cases (null, empty, boundary)
- Error cases
- Async behavior
- Mocks cleaned up
🤖 AI Test Generation
Auto-Generate Test Cases
// Given a function like:
function validateEmail(email) {
return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email);
}
// AI generates these test cases:
describe('validateEmail', () => {
// Happy path
test('valid email returns true', () => {
expect(validateEmail('[email protected]')).toBe(true);
});
// Edge cases
test.each([
['', false], // empty
['user', false], // no @
['user@', false], // no domain
['@example.com', false], // no user
['user@example', false], // no TLD
['[email protected]', true], // multiple dots
])('validateEmail(%s) = %s', (input, expected) => {
expect(validateEmail(input)).toBe(expected);
});
});
📊 Coverage Analysis
Commands
# Jest coverage
npm test -- --coverage
# Vitest coverage
npx vitest --coverage
# NYC coverage
npx nyc npm test
Coverage Targets
| Metric | Minimum | Good |
|---|---|---|
| Statements | 70% | 90%+ |
| Branches | 70% | 85%+ |
| Functions | 70% | 90%+ |
| Lines | 70% | 90%+ |
📸 Snapshot Testing
// Generate snapshot
test('component renders correctly', () => {
const tree = render(<Button label="Click me" />);
expect(tree).toMatchSnapshot();
});
// Update snapshots
// npm test -- -u
Test Commands
# Run all tests
npm test
# Run specific file
npm test -- button.test.js
# Watch mode
npm test -- --watch
# Update snapshots
npm test -- -u
# Coverage report
npm test -- --coverage --coverageReporters=text
Установить testing в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл testing?
Write and run tests including unit tests, integration tests, and E2E tests. Use when ensuring code quality, writing test cases, or setting up testing frameworks.
Как установить скилл testing?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл testing запускает скрипты?
Нет, скилл состоит только из инструкций (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