Appearance
Giai đoạn Kiểm thử (Testing)
Xây dựng chiến lược kiểm thử và viết tests.
Mục đích
- Định nghĩa test strategy
- Viết unit tests
- Viết integration tests
- Đảm bảo coverage
Cách thực hiện
1. Viết tests
/writing-test2. Review coverage
bash
npm run test -- --coverageTemplate nội dung
markdown
---
phase: testing
title: Feature Name Testing
---
# Kiểm thử: [Tên Tính năng]
## Coverage mục tiêu
| Loại | Target | Hiện tại |
|------|--------|----------|
| Unit | 80% | 85% |
| Integration | 70% | 72% |
| E2E | 50% | 55% |
## Unit Tests
### Service Layer
\`\`\`typescript
describe('FeatureService', () => {
it('should create feature', async () => {
const result = await service.create({ name: 'Test' });
expect(result.id).toBeDefined();
});
it('should throw on invalid input', async () => {
await expect(service.create({}))
.rejects.toThrow('Validation error');
});
});
\`\`\`
### Edge Cases
| Scenario | Expected | Status |
|----------|----------|--------|
| Empty input | Throw error | ✅ |
| Duplicate name | Return existing | ✅ |
| Very long name | Truncate | ⏳ |
## Integration Tests
### API Endpoints
\`\`\`typescript
describe('POST /api/features', () => {
it('should create and return 201', async () => {
const res = await request(app)
.post('/api/features')
.send({ name: 'Test' });
expect(res.status).toBe(201);
});
});
\`\`\`
## Manual Testing Checklist
- [ ] Tạo feature mới
- [ ] Xem danh sách features
- [ ] Cập nhật feature
- [ ] Xóa feature
- [ ] Validate error messages
## Kết quả
\`\`\`
Test Suites: 5 passed, 5 total
Tests: 42 passed, 42 total
Coverage: 87%
\`\`\`Commands hữu ích
bash
# Run all tests
npm test
# Run with coverage
npm run test -- --coverage
# Run specific file
npm test -- feature.test.ts
# Watch mode
npm test -- --watch