Appearance
/writing-test
Viết tests cho code changes nhắm 100% coverage.
Mô tả
Command này hướng dẫn viết unit tests, integration tests và manual testing checklist.
Cách sử dụng
/writing-testQuy trình
Bước 1: Thu thập context
- Tên feature và branch
- Tóm tắt changes
- Môi trường (backend/frontend)
- Test suites hiện có
Bước 2: Unit Tests
Với mỗi module/function:
- Liệt kê scenarios (happy path, edge cases, errors)
- Generate test cases với assertions
- Highlight missing coverage
Bước 3: Integration Tests
- Xác định critical flows
- Setup/teardown steps
- Test interaction boundaries
Bước 4: Manual Testing
- Checklist UX
- Accessibility
- Error handling
Ví dụ output
typescript
describe('AuthService', () => {
describe('login', () => {
it('should return token for valid credentials', async () => {
const result = await authService.login({
email: 'test@example.com',
password: 'password123'
});
expect(result.token).toBeDefined();
expect(result.user.email).toBe('test@example.com');
});
it('should throw for invalid password', async () => {
await expect(authService.login({
email: 'test@example.com',
password: 'wrong'
})).rejects.toThrow('Invalid credentials');
});
});
});Coverage Strategy
bash
npm run test -- --coverage
# Target
Statements: 80%+
Branches: 75%+
Functions: 80%+
Lines: 80%+