Instruction file imported from baijum/kanakku (
.cursor/rules/testing.mdc). Copyright stays with the author.
Philosophy
Testing philosophy
- Update tests to match intended implementation unless:
- Implementation is clearly wrong
- Security risk exists
- Test reflects documented requirements Applies to: /.test.{js,jsx,ts,tsx,py},test_.py,/tests/**/*
General Standards
General testing standards
- Test all critical functionality
- Always pass before production
- Consider different environments
- Only mock data for tests
Backend
Backend testing standards
- Use pytest with fixtures
- Separate test database
- Test all API endpoints
- Mock external dependencies
- Use parameterized tests
- Leverage existing fixtures
Frontend
Frontend testing standards
- Use React Testing Library
- Test user behavior, not implementation
- Mock API calls (prefer MSW)
- Test critical user flows
- Test accessibility
- Provide necessary contexts
- Use snapshot testing sparingly
Organization
Test organization
- Group related tests
- Use descriptive names
- Follow AAA pattern
- Backend:
tests/mirrorsapp/ - Frontend: Co-locate test files
Coverage
Test coverage standards
- 80%+ on core features
- Test edge cases
- Include positive/negative tests
- Performance tests for critical ops
Test Data
Test data management
- Backend: Use factory_boy
- Frontend: Mock data helpers
- Clean up after tests
- Use realistic anonymized data
- Minimal sufficient data
Api Testing
API testing standards
- Test all HTTP methods
- Verify status codes
- Test validation/errors
- Test auth for protected endpoints
- Validate response schemas
E2E
End-to-end testing
- Use Playwright
- Test critical user journeys
- Cross-browser/device tests
- Test with different user roles
Performance
Performance testing
- Load test critical APIs
- Test query performance
- Monitor memory usage
- Benchmark critical ops
Security Testing
Security testing
- Test auth mechanisms
- Verify input validation
- Test for common vulnerabilities
- Test rate limiting
- Verify no sensitive data exposure
Ci
CI standards
- All tests pass before merge
- Run on every PR
- Include linting/quality checks
- Run security scans
- Publish coverage reports
Maintenance
Test maintenance
- Regularly review/update tests
- Remove obsolete tests
- Refactor for maintainability
- Keep test deps updated
- Document complex scenarios