Loading...
Loading...
Compare original and translation side by side
| Priority | Category | Impact | Prefix |
|---|---|---|---|
| 1 | Test Structure | CRITICAL | |
| 2 | Test Isolation | CRITICAL | |
| 3 | Assertions | HIGH | |
| 4 | Test Data | HIGH | |
| 5 | Mocking | MEDIUM | |
| 6 | Coverage | MEDIUM | |
| 7 | Performance | LOW | |
| 优先级 | 类别 | 影响程度 | 前缀 |
|---|---|---|---|
| 1 | 测试结构 | 关键 | |
| 2 | 测试隔离 | 关键 | |
| 3 | 断言 | 高 | |
| 4 | 测试数据 | 高 | |
| 5 | 模拟(Mocking) | 中 | |
| 6 | 覆盖率 | 中 | |
| 7 | 性能 | 低 | |
struct-aaastruct-namingstruct-one-assertstruct-describe-itstruct-given-when-thenstruct-aaastruct-namingstruct-one-assertstruct-describe-itstruct-given-when-theniso-independentiso-no-shared-stateiso-deterministiciso-no-order-dependencyiso-cleanupiso-independentiso-no-shared-stateiso-deterministiciso-no-order-dependencyiso-cleanupassert-specificassert-meaningful-messagesassert-expected-firstassert-no-magic-numbersassert-specificassert-meaningful-messagesassert-expected-firstassert-no-magic-numbersdata-factoriesdata-minimaldata-realisticdata-fixturesdata-factoriesdata-minimaldata-realisticdata-fixturesmock-only-boundariesmock-verify-interactionsmock-minimalmock-realisticmock-only-boundariesmock-verify-interactionsmock-minimalmock-realisticcov-meaningfulcov-edge-casescov-unhappy-pathscov-not-100-percentcov-meaningfulcov-edge-casescov-unhappy-pathscov-not-100-percentperf-fast-unitperf-slow-integrationperf-parallelperf-fast-unitperf-slow-integrationperf-parallelrules/rules/it('calculates total with discount', () => {
// Arrange - set up test data
const cart = new ShoppingCart();
cart.addItem({ name: 'Book', price: 20 });
cart.applyDiscount(0.1);
// Act - execute the code under test
const total = cart.getTotal();
// Assert - verify the result
expect(total).toBe(18);
});it('calculates total with discount', () => {
// Arrange - set up test data
const cart = new ShoppingCart();
cart.addItem({ name: 'Book', price: 20 });
cart.applyDiscount(0.1);
// Act - execute the code under test
const total = cart.getTotal();
// Assert - verify the result
expect(total).toBe(18);
});// ✅ Describes behavior and scenario
describe('UserService.register', () => {
it('creates user with hashed password', () => {});
it('throws ValidationError when email is invalid', () => {});
it('sends welcome email after successful registration', () => {});
});
// ❌ Vague names
it('test1', () => {});
it('should work', () => {});// ✅ Describes behavior and scenario
describe('UserService.register', () => {
it('creates user with hashed password', () => {});
it('throws ValidationError when email is invalid', () => {});
it('sends welcome email after successful registration', () => {});
});
// ❌ Vague names
it('test1', () => {});
it('should work', () => {});// ✅ Each test sets up its own data
beforeEach(() => {
mockRepository = { save: jest.fn(), find: jest.fn() };
service = new OrderService(mockRepository);
});
// ❌ Shared state between tests
let globalOrder: Order; // Tests depend on each other// ✅ Each test sets up its own data
beforeEach(() => {
mockRepository = { save: jest.fn(), find: jest.fn() };
service = new OrderService(mockRepository);
});
// ❌ Shared state between tests
let globalOrder: Order; // Tests depend on each other /\
/ \ E2E Tests (few)
/----\ - Test critical user flows
/ \ - Slow, expensive
/--------\ Integration Tests (some)
/ \ - Test component interactions
/------------\ - Database, API calls
/ \ Unit Tests (many)
/----------------\ - Fast, isolated
- Test single units /\
/ \ E2E Tests (few)
/----\ - Test critical user flows
/ \ - Slow, expensive
/--------\ Integration Tests (some)
/ \ - Test component interactions
/------------\ - Database, API calls
/ \ Unit Tests (many)
/----------------\ - Fast, isolated
- Test single unitsfile:line - [category] Description of issuetests/user.test.ts:15 - [struct] Missing Arrange/Act/Assert separation
tests/order.test.ts:42 - [iso] Test depends on previous test's state
tests/cart.test.ts:28 - [assert] Multiple unrelated assertions in one testfile:line - [category] Description of issuetests/user.test.ts:15 - [struct] Missing Arrange/Act/Assert separation
tests/order.test.ts:42 - [iso] Test depends on previous test's state
tests/cart.test.ts:28 - [assert] Multiple unrelated assertions in one testrules/struct-aaa-pattern.md
rules/iso-independent-tests.md
rules/data-factories.mdrules/struct-aaa-pattern.md
rules/iso-independent-tests.md
rules/data-factories.mdrules/rules/