跳到正文
cccskills
免费在 GitHub 公开

testing-strategist

Comprehensive testing strategies including unit tests, integration tests, E2E tests, property-based testing, visual regression, and test automation. Use when writing tests, setting up testing frameworks, or designing test coverage strategies.

中文简介正在准备中。当前显示原文说明。

集成工具Playwright
查看安装方法

包含的文件(1)

  • SKILL.md4.5 KB

SKILL.md(原文)

安装前可以查看交给 AI 代理的指令内容。

Testing Strategist

Testing Pyramid

    /\
   /  \  E2E Tests (Playwright) - 10%
  /____\
 /      \ Integration Tests - 30%
/________\
Unit Tests (Jest/Vitest) - 60%

Unit Testing

Component Tests

import { render, screen, fireEvent } from '@testing-library/react';
import { UserProfile } from './UserProfile';

describe('UserProfile', () => {
  it('renders user information', () => {
    const user = { name: 'John', email: 'john@example.com' };
    render(<UserProfile user={user} />);
    
    expect(screen.getByText('John')).toBeInTheDocument();
    expect(screen.getByText('john@example.com')).toBeInTheDocument();
  });
  
  it('handles edit action', () => {
    const onEdit = vi.fn();
    render(<UserProfile user={user} onEdit={onEdit} />);
    
    fireEvent.click(screen.getByText('Edit'));
    expect(onEdit).toHaveBeenCalled();
  });
});

Custom Hook Tests

import { renderHook, act } from '@testing-library/react';
import { useCounter } from './useCounter';

describe('useCounter', () => {
  it('increments counter', () => {
    const { result } = renderHook(() => useCounter(0));
    
    act(() => {
      result.current.increment();
    });
    
    expect(result.current.count).toBe(1);
  });
});

Integration Testing

API Route Tests

import { createTestServer } from '@/test/utils';

describe('POST /api/users', () => {
  const server = createTestServer();
  
  it('creates user with valid data', async () => {
    const response = await server
      .post('/api/users')
      .send({ email: 'test@example.com', password: 'Secure123!' })
      .expect(201);
    
    expect(response.body.data.email).toBe('test@example.com');
  });
  
  it('rejects invalid email', async () => {
    await server
      .post('/api/users')
      .send({ email: 'invalid', password: 'pass' })
      .expect(400);
  });
});

Database Integration

describe('UserRepository', () => {
  beforeEach(async () => {
    await db.delete(users);
  });
  
  it('creates and retrieves user', async () => {
    const user = await userRepo.create({
      email: 'test@example.com',
      name: 'Test User'
    });
    
    const retrieved = await userRepo.findById(user.id);
    expect(retrieved?.email).toBe('test@example.com');
  });
});

E2E Testing (Playwright)

import { test, expect } from '@playwright/test';

test.describe('Authentication Flow', () => {
  test('user can log in', 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('Dashboard');
  });
  
  test('shows error for invalid credentials', async ({ page }) => {
    await page.goto('/login');
    
    await page.fill('[name="email"]', 'wrong@example.com');
    await page.fill('[name="password"]', 'wrong');
    await page.click('button[type="submit"]');
    
    await expect(page.locator('.error')).toContainText('Invalid credentials');
  });
});

Property-Based Testing

import { fc, test } from '@fast-check/vitest';

test.prop([fc.array(fc.integer())])('sort is idempotent', (arr) => {
  const sorted = [...arr].sort((a, b) => a - b);
  const sortedAgain = [...sorted].sort((a, b) => a - b);
  expect(sorted).toEqual(sortedAgain);
});

Test Coverage Strategy

// vitest.config.ts
export default defineConfig({
  test: {
    coverage: {
      provider: 'v8',
      reporter: ['text', 'json', 'html'],
      thresholds: {
        lines: 80,
        functions: 80,
        branches: 70,
        statements: 80
      },
      exclude: [
        '**/*.config.*',
        '**/node_modules/**',
        '**/__tests__/**'
      ]
    }
  }
});

Mocking Patterns

// Mock external services
vi.mock('@/integrations/stripe', () => ({
  createPaymentIntent: vi.fn().mockResolvedValue({
    clientSecret: 'secret_123'
  })
}));

// Mock database
vi.mock('@/db', () => ({
  db: {
    query: {
      users: {
        findFirst: vi.fn()
      }
    }
  }
}));

评价

还没有评价。欢迎分享你的使用感受。

评论

无需登录即可发表。欢迎分享使用感受、提问,或说明在哪些环境下无法运行。

还没有评论。来写第一条吧。

提交后会立即公开。请勿填写邮箱、电话等个人信息。URL 最多 2 个。

0 / 1000 字

此表单受 reCAPTCHA 保护,适用 Google 的隐私权政策和服务条款。

同一仓库的技能

ai-sdk

免费

Vercel AI SDK expert guidance. Use when building AI-powered features — chat interfaces, text generation, structured output, tool calling, agents, MCP integration, streaming, embeddings, reranking, image generation, or working with any LLM provider.

中文简介正在准备中。当前显示原文说明。

garochee33/DSH42026年10月19日 更新

Algorithm design and analysis skill for DSH; use when working on optimization, data structures, or computational procedures.

中文简介正在准备中。当前显示原文说明。

garochee33/DSH42026年10月19日 更新

Design and implement scalable API gateways, RESTful APIs, GraphQL endpoints, WebSocket handlers, and microservice communication patterns. Use when creating API routes, designing endpoints, implementing middleware, or setting up service mesh architectures.

中文简介正在准备中。当前显示原文说明。

garochee33/DSH42026年10月19日 更新

best-of-n

免费

Implement a task N ways in parallel and pick the best. Spawns multiple subagents in isolated worktrees, evaluates all candidates, and applies the winner. Use when asked to "best of n", "try multiple approaches", "parallel implementations", "/best-of-n", or "/bon".

中文简介正在准备中。当前显示原文说明。

garochee33/DSH42026年10月19日 更新

check

免费

Check your work with a verification subagent. Spawns a verifier that reviews diffs, runs builds and tests, and evaluates correctness. Use when asked to "check work", "verify changes", "self-verify", "/check", "/verify", "/check-work", or "/self-verify".

中文简介正在准备中。当前显示原文说明。

garochee33/DSH42026年10月19日 更新

CI/CD pipeline design, GitHub Actions workflows, deployment automation, infrastructure as code, and release management. Use when setting up CI/CD, automating deployments, configuring build pipelines, or managing releases.

中文简介正在准备中。当前显示原文说明。

garochee33/DSH42026年10月19日 更新

查看 garochee33 的全部技能

报告此技能的问题