Initial commit: add .gitignore and README
This commit is contained in:
230
TESTING_STANDARDS.md
Normal file
230
TESTING_STANDARDS.md
Normal file
@@ -0,0 +1,230 @@
|
||||
# Testing Standards
|
||||
|
||||
**Last Updated**: 2025-01-27
|
||||
**Purpose**: Standardized testing guidelines for all projects
|
||||
|
||||
---
|
||||
|
||||
## Overview
|
||||
|
||||
This document establishes testing standards and best practices for all projects in the workspace.
|
||||
|
||||
---
|
||||
|
||||
## Testing Stack
|
||||
|
||||
### TypeScript/JavaScript Projects
|
||||
- **Unit Tests**: Vitest (recommended) or Jest
|
||||
- **Integration Tests**: Vitest or Jest with test database
|
||||
- **E2E Tests**: Playwright (recommended) or Cypress
|
||||
- **API Tests**: Vitest/Jest with Supertest
|
||||
|
||||
### Solidity Projects
|
||||
- **Unit Tests**: Foundry (forge test)
|
||||
- **Integration Tests**: Foundry with fork testing
|
||||
- **Fuzz Tests**: Foundry fuzzing
|
||||
- **Invariant Tests**: Foundry invariant testing
|
||||
|
||||
### Python Projects
|
||||
- **Unit Tests**: pytest
|
||||
- **Integration Tests**: pytest with fixtures
|
||||
- **E2E Tests**: pytest with Selenium/Playwright
|
||||
|
||||
---
|
||||
|
||||
## Coverage Requirements
|
||||
|
||||
### Minimum Coverage
|
||||
- **Unit Tests**: 80% coverage minimum
|
||||
- **Critical Paths**: 100% coverage
|
||||
- **Integration Tests**: Cover major workflows
|
||||
- **E2E Tests**: Cover user journeys
|
||||
|
||||
### Coverage Reporting
|
||||
- Generate coverage reports
|
||||
- Track coverage over time
|
||||
- Set coverage thresholds
|
||||
- Fail builds below threshold
|
||||
|
||||
---
|
||||
|
||||
## Test Structure
|
||||
|
||||
### Directory Structure
|
||||
```
|
||||
tests/
|
||||
├── unit/ # Unit tests
|
||||
│ └── [component].test.ts
|
||||
├── integration/ # Integration tests
|
||||
│ └── [feature].test.ts
|
||||
├── e2e/ # End-to-end tests
|
||||
│ └── [scenario].spec.ts
|
||||
└── fixtures/ # Test fixtures
|
||||
└── [fixtures]
|
||||
```
|
||||
|
||||
### Naming Conventions
|
||||
- Unit tests: `[component].test.ts`
|
||||
- Integration tests: `[feature].integration.test.ts`
|
||||
- E2E tests: `[scenario].e2e.spec.ts`
|
||||
|
||||
---
|
||||
|
||||
## Testing Best Practices
|
||||
|
||||
### Unit Tests
|
||||
- Test individual functions/components
|
||||
- Mock external dependencies
|
||||
- Test edge cases
|
||||
- Keep tests fast
|
||||
- Use descriptive test names
|
||||
|
||||
### Integration Tests
|
||||
- Test component interactions
|
||||
- Use test databases
|
||||
- Clean up after tests
|
||||
- Test error scenarios
|
||||
- Verify data consistency
|
||||
|
||||
### E2E Tests
|
||||
- Test user workflows
|
||||
- Use realistic data
|
||||
- Test critical paths
|
||||
- Keep tests stable
|
||||
- Use page object model
|
||||
|
||||
---
|
||||
|
||||
## Test Execution
|
||||
|
||||
### Local Development
|
||||
```bash
|
||||
# Run all tests
|
||||
pnpm test
|
||||
|
||||
# Run unit tests only
|
||||
pnpm test:unit
|
||||
|
||||
# Run integration tests
|
||||
pnpm test:integration
|
||||
|
||||
# Run E2E tests
|
||||
pnpm test:e2e
|
||||
|
||||
# Run with coverage
|
||||
pnpm test:coverage
|
||||
```
|
||||
|
||||
### CI/CD
|
||||
- Run tests on every commit
|
||||
- Run full test suite on PR
|
||||
- Run E2E tests on main branch
|
||||
- Fail builds on test failure
|
||||
- Generate coverage reports
|
||||
|
||||
---
|
||||
|
||||
## Test Data Management
|
||||
|
||||
### Fixtures
|
||||
- Use fixtures for test data
|
||||
- Keep fixtures realistic
|
||||
- Update fixtures as needed
|
||||
- Document fixture purpose
|
||||
|
||||
### Test Databases
|
||||
- Use separate test databases
|
||||
- Reset between tests
|
||||
- Use migrations
|
||||
- Seed test data
|
||||
|
||||
---
|
||||
|
||||
## Performance Testing
|
||||
|
||||
### Requirements
|
||||
- Test critical paths
|
||||
- Set performance budgets
|
||||
- Monitor performance metrics
|
||||
- Load testing for APIs
|
||||
|
||||
### Tools
|
||||
- Lighthouse for web apps
|
||||
- k6 for API load testing
|
||||
- Web Vitals for frontend
|
||||
- Performance profiling
|
||||
|
||||
---
|
||||
|
||||
## Security Testing
|
||||
|
||||
### Requirements
|
||||
- Test authentication/authorization
|
||||
- Test input validation
|
||||
- Test security headers
|
||||
- Test dependency vulnerabilities
|
||||
|
||||
### Tools
|
||||
- npm audit / pnpm audit
|
||||
- Snyk
|
||||
- OWASP ZAP
|
||||
- Security linters
|
||||
|
||||
---
|
||||
|
||||
## Test Maintenance
|
||||
|
||||
### Regular Updates
|
||||
- Update tests with code changes
|
||||
- Remove obsolete tests
|
||||
- Refactor tests as needed
|
||||
- Keep tests fast
|
||||
|
||||
### Test Reviews
|
||||
- Review tests in PRs
|
||||
- Ensure adequate coverage
|
||||
- Verify test quality
|
||||
- Document test strategy
|
||||
|
||||
---
|
||||
|
||||
## Examples
|
||||
|
||||
### TypeScript Unit Test Example
|
||||
```typescript
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { myFunction } from './myFunction';
|
||||
|
||||
describe('myFunction', () => {
|
||||
it('should return expected result', () => {
|
||||
expect(myFunction(input)).toBe(expectedOutput);
|
||||
});
|
||||
});
|
||||
```
|
||||
|
||||
### Solidity Test Example
|
||||
```solidity
|
||||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.8.0;
|
||||
|
||||
import "forge-std/Test.sol";
|
||||
import "../src/MyContract.sol";
|
||||
|
||||
contract MyContractTest is Test {
|
||||
MyContract public contract;
|
||||
|
||||
function setUp() public {
|
||||
contract = new MyContract();
|
||||
}
|
||||
|
||||
function testFunction() public {
|
||||
// Test implementation
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
**Last Updated**: 2025-01-27
|
||||
**Next Review**: Q2 2025
|
||||
|
||||
Reference in New Issue
Block a user