Testing Guidelines
November 16, 2025 · View on GitHub
Test Coverage Requirements
Minimum: 80% coverage across all code
Test Types
Unit Tests
describe('ConsentManager', () => {
it('should record user consent', async () => {
const result = await consentManager.recordConsent({
userId: 'test-user',
consentType: ConsentType.ANALYTICS,
granted: true,
timestamp: new Date()
});
expect(result).toBeDefined();
});
});
Integration Tests
describe('API Integration', () => {
it('should authenticate and fetch user profile', async () => {
const token = await login('test@azora.world', 'password');
const profile = await getProfile(token);
expect(profile.email).toBe('test@azora.world');
});
});
E2E Tests
test('Complete user journey', async ({ page }) => {
await page.goto('/signup');
await page.fill('[name="email"]', 'test@azora.world');
await page.click('button[type="submit"]');
await expect(page).toHaveURL('/dashboard');
});
Running Tests
# All tests
npm test
# Unit tests only
npm run test:unit
# Integration tests
npm run test:integration
# E2E tests
npm run test:e2e
# With coverage
npm run test:coverage
# Watch mode
npm run test:watch
Test Structure
tests/
├── unit/ # Unit tests
├── integration/ # Integration tests
├── e2e/ # End-to-end tests
└── performance/ # Load tests
Best Practices
- Arrange-Act-Assert: Structure tests clearly
- One Assertion: Test one thing per test
- Descriptive Names: Use clear test descriptions
- Mock External: Mock external dependencies
- Clean Up: Reset state after tests
Coverage Enforcement
Coverage checked in CI/CD:
{
"coverageThreshold": {
"global": {
"branches": 80,
"functions": 80,
"lines": 80,
"statements": 80
}
}
}