From charon-fan-agent-playbook
Creates and maintains unit, integration, and E2E automated tests using Jest, Supertest, and Playwright examples. Useful for writing tests, automating testing, or improving coverage.
npx claudepluginhub zhaono1/agent-playbookThis skill is limited to using the following tools:
Expert in creating and maintaining automated tests for various frameworks and languages.
Designs testing strategies, selects frameworks, and provides templates for unit, integration, and E2E tests in JS/TS (Vitest, Jest, Playwright), Python (pytest), and Go codebases.
Designs testing strategies using the pyramid (70% unit, 20% integration, 10% E2E). Guides test types, TDD implementation, and best practices for code quality.
Share bugs, ideas, or general feedback.
Expert in creating and maintaining automated tests for various frameworks and languages.
Activates when you:
/\
/E2E\ - Few, expensive, slow
/------\
/ Integration \ - Moderate number
/--------------\
/ Unit Tests \ - Many, cheap, fast
/------------------\
describe('UserService', () => {
describe('createUser', () => {
it('should create a user with valid data', async () => {
// Arrange
const userData = {
name: 'John Doe',
email: 'john@example.com'
};
// Act
const user = await userService.create(userData);
// Assert
expect(user.id).toBeDefined();
expect(user.email).toBe(userData.email);
});
it('should throw error for invalid email', async () => {
// Arrange
const userData = { email: 'invalid' };
// Act & Assert
await expect(userService.create(userData))
.rejects.toThrow('Invalid email');
});
});
});
describe('POST /api/users', () => {
it('should create a user', async () => {
const response = await request(app)
.post('/api/users')
.send({
name: 'John Doe',
email: 'john@example.com'
})
.expect(201)
.expect((res) => {
expect(res.body.id).toBeDefined();
expect(res.body.email).toBe('john@example.com');
});
});
});
test('user can login', async ({ page }) => {
await page.goto('/login');
await page.fill('[name="email"]', 'user@example.com');
await page.fill('[name="password"]', 'password123');
await page.click('button[type="submit"]');
await expect(page).toHaveURL('/dashboard');
await expect(page.locator('h1')).toContainText('Welcome');
});
| Type | Target |
|---|---|
| Lines | > 80% |
| Branches | > 75% |
| Functions | > 80% |
| Statements | > 80% |
# Jest
npm test -- --coverage
# Python (pytest-cov)
pytest --cov=src --cov-report=html
# Go
go test -coverprofile=coverage.out
go tool cover -html=coverage.out
// Good: Describes what is being tested
it('should reject invalid email addresses')
// Good: Describes the scenario and outcome
it('returns 401 when user provides invalid credentials')
// Bad: Vague
it('works correctly')
| Language | Framework | Command |
|---|---|---|
| TypeScript/JS | Jest, Vitest | npm test |
| Python | pytest | pytest |
| Go | testing | go test |
| Java | JUnit | mvn test |
| Rust | built-in | cargo test |
Generate test boilerplate:
python scripts/generate_test.py <filename>
Check test coverage:
python scripts/coverage_report.py
references/best-practices.md - Testing best practicesreferences/examples/ - Framework-specific examplesreferences/mocking.md - Mocking guidelines