AgentSkillsCN

testing-standards

测试编写标准。在编写测试或进行测试评审时,自动应用这些标准。

SKILL.md
--- frontmatter
name: testing-standards
description: "Test yazım standartları. TEST YAZARKEN veya TEST REVIEW yaparken otomatik uygula."

Testing Standards

Test Piramidi

code
       /\        E2E (10%) - Critical user paths
      /  \
     /────\      Integration (20%) - API, service
    /      \
   /────────\    Unit (70%) - Business logic

Test Yapısı (AAA)

typescript
describe('UserService', () => {
  describe('createUser', () => {
    it('should create user with valid data', async () => {
      // Arrange
      const input = { email: 'test@example.com', name: 'Test' }
      
      // Act
      const result = await userService.createUser(input)
      
      // Assert
      expect(result.email).toBe(input.email)
    })
  })
})

İsimlendirme

typescript
// ✅ Doğru
it('should return user when valid id provided')
it('should throw NotFoundError when user does not exist')

// ❌ Yanlış
it('should work correctly')
it('test createUser')

Best Practices

Bağımsızlık

typescript
beforeEach(() => {
  jest.clearAllMocks()
  // Fresh state her testte
})

Edge Cases

typescript
describe('calculateDiscount', () => {
  it('should apply discount at exactly 100', () => {...})
  it('should not apply below 100', () => {...})
  it('should throw for negative', () => {...})
  it('should handle null', () => {...})
})

Mocking

typescript
// ✅ External dependency mock
const mockEmailService = {
  send: jest.fn().mockResolvedValue(true)
}

// ❌ Internal helper mocklamaktan kaçın

API Testing

typescript
describe('POST /api/users', () => {
  it('should create user (201)', async () => {
    const response = await request(app)
      .post('/api/users')
      .send({ email: 'test@test.com', name: 'Test' })
      .expect(201)
    
    expect(response.body.success).toBe(true)
  })

  it('should return 400 for invalid email', async () => {
    await request(app)
      .post('/api/users')
      .send({ email: 'invalid' })
      .expect(400)
  })
})

E2E Testing

typescript
test('user registration flow', async ({ page }) => {
  await page.goto('/register')
  await page.fill('[data-testid="email"]', 'test@example.com')
  await page.click('[data-testid="submit"]')
  await expect(page).toHaveURL('/dashboard')
})

Coverage Hedefleri

TürMinimumİdeal
Unit70%85%
IntegrationKritik path80%

Checklist

  • Tek bir şeyi test ediyor
  • Bağımsız çalışıyor
  • Açıklayıcı ismi var
  • AAA pattern
  • Edge case'ler