
Codex Skill
当用户要求使用 Codex、GPT-5 或 GPT-5.1 实现功能(通常为实现 Claude 设计的计划或功能)时使用。提供非交互式……
若项目中已配置测试框架,则直接沿用。若项目尚无测试技术栈,则按以下优先级选择:
| 语言 | 单元测试 | 集成测试 | 端到端测试 |
|---|---|---|---|
| TypeScript / JavaScript | Vitest | Supertest | Playwright |
| Python | pytest | pytest + httpx | Playwright |
| Swift | XCTest | XCTest | XCUITest |
npm install -D vitest @testing-library/react @testing-library/jest-dom npx vitest npx vitest run npx vitest --coverage
当项目需要基础配置时,可采用如下默认配置:
import { defineConfig } from 'vitest/config'
export default defineConfig({
test: {
globals: true,
environment: 'jsdom',
setupFiles: './tests/setup.ts',
},
})
npm install -D jest @types/jest ts-jest npx jest npx jest --watch npx jest --coverage npx jest path/to/test
uv pip install pytest pytest-cov pytest-asyncio httpx pytest pytest -v pytest -x pytest --cov=app pytest tests/test_api.py -k "test_login" pytest --tb=short
swift test swift test --filter MyTests swift test --parallel
npm install -D @playwright/test npx playwright install npx playwright test npx playwright test --headed npx playwright test --debug npx playwright test --project=chromium npx playwright show-report
test('calculates total with tax', () => {
const cart = new Cart([{ price: 100, qty: 2 }])
const total = cart.totalWithTax(0.08)
expect(total).toBe(216)
})
test('fetches user data', async () => {
const user = await getUser('123')
expect(user.name).toBe('Colt')
})
import { vi } from 'vitest'
const mockFetch = vi.fn().mockResolvedValue({
json: () => Promise.resolve({ id: 1, name: 'Test' }),
})
vi.stubGlobal('fetch', mockFetch)
import pytest
from httpx import AsyncClient
from app.main import app
@pytest.mark.asyncio
async def test_get_users():
async with AsyncClient(app=app, base_url="http://test") as client:
response = await client.get("/users")
assert response.status_code == 200
assert isinstance(response.json(), list)
import { fireEvent, render, screen } from '@testing-library/react'
import { Button } from './Button'
test('calls onClick when clicked', () => {
const handleClick = vi.fn()
render(Click me)
fireEvent.click(screen.getByText('Click me'))
expect(handleClick).toHaveBeenCalledOnce()
})
# JavaScript / TypeScript npx vitest --coverage npx jest --coverage # Python pytest --cov=app --cov-report=html pytest --cov=app --cov-report=term pytest --cov=app --cov-fail-under=80
务必覆盖以下方面:
null、极值等通常无需测试:
|
1 |
|







