Loading...
Loading...
Compare original and translation side by side
/tdd # 対話的にTDDを開始
/tdd UserService # UserServiceのテストから開始
/tdd handlePayment edge # handlePaymentのエッジケーステスト/tdd # 以互动方式启动TDD
/tdd UserService # 从编写UserService的测试开始
/tdd handlePayment edge # 编写handlePayment的边缘场景测试┌─────────────────────────────────────────────────┐
│ 1. RED → テストを書く(失敗することを確認) │
│ 2. GREEN → 最小限のコードで通す │
│ 3. REFACTOR → リファクタ(テストは通ったまま)│
└─────────────────────────────────────────────────┘┌─────────────────────────────────────────────────┐
│ 1. RED → 编写测试(确认测试失败) │
│ 2. GREEN → 用最少的代码让测试通过 │
│ 3. REFACTOR → 重构(确保测试仍能通过)│
└─────────────────────────────────────────────────┘// tests/unit/services/user.service.test.ts
describe('UserService', () => {
describe('createUser', () => {
it('should create user with valid data', async () => {
const result = await userService.createUser({
email: 'test@example.com',
name: 'Test User',
});
expect(result.id).toBeDefined();
expect(result.email).toBe('test@example.com');
});
it('should throw error for duplicate email', async () => {
// エッジケース
await expect(
userService.createUser({ email: 'existing@example.com', name: 'Test' })
).rejects.toThrow('Email already exists');
});
});
});npm run test -- --watch tests/unit/services/user.service.test.ts// tests/unit/services/user.service.test.ts
describe('UserService', () => {
describe('createUser', () => {
it('should create user with valid data', async () => {
const result = await userService.createUser({
email: 'test@example.com',
name: 'Test User',
});
expect(result.id).toBeDefined();
expect(result.email).toBe('test@example.com');
});
it('should throw error for duplicate email', async () => {
// 边缘场景
await expect(
userService.createUser({ email: 'existing@example.com', name: 'Test' })
).rejects.toThrow('Email already exists');
});
});
});npm run test -- --watch tests/unit/services/user.service.test.tsdescribe('[対象]', () => {
describe('[メソッド/機能]', () => {
it('should [期待する動作] when [条件]', () => {
// ...
});
});
});describe('[测试对象]', () => {
describe('[方法/功能]', () => {
it('should [预期行为] when [条件]', () => {
// ...
});
});
});| ケース | 例 |
|---|---|
| 正常系 | 有効な入力で期待通り動作 |
| 境界値 | 0, 空文字, 配列の最初/最後 |
| エラー系 | 無効な入力、null/undefined |
| エッジケース | 並行アクセス、タイムアウト |
| 场景 | 示例 |
|---|---|
| 正常场景 | 有效输入下按预期运行 |
| 边界值 | 0、空字符串、数组的首个/末尾元素 |
| 错误场景 | 无效输入、null/undefined |
| 边缘场景 | 并发访问、超时 |
// 外部依存はモック
vi.mock('@/db', () => ({
db: {
select: vi.fn().mockReturnValue({
from: vi.fn().mockReturnValue({
where: vi.fn().mockResolvedValue([{ id: '1', name: 'Test' }]),
}),
}),
},
}));// 外部依赖使用Mock
vi.mock('@/db', () => ({
db: {
select: vi.fn().mockReturnValue({
from: vi.fn().mockReturnValue({
where: vi.fn().mockResolvedValue([{ id: '1', name: 'Test' }]),
}),
}),
},
}));npm run test # 全テスト
npm run test -- --watch # ウォッチモード
npm run test -- tests/unit/specific # 特定ディレクトリ
npm run test -- --coverage # カバレッジnpm run test # 运行所有测试
npm run test -- --watch # 监听模式
npm run test -- tests/unit/specific # 运行指定目录的测试
npm run test -- --coverage # 生成测试覆盖率报告npm test # 全テスト
npm test -- --watch # ウォッチモード
npm test -- --coverage # カバレッジnpm test # 运行所有测试
npm test -- --watch # 监听模式
npm test -- --coverage # 生成测试覆盖率报告npm run test:e2e # 全E2E
npx playwright test --grep "login" # 特定テストnpm run test:e2e # 运行所有E2E测试
npx playwright test --grep "login" # 运行指定测试