This framework provides comprehensive automated testing for the NEPA platform APIs, including unit tests, integration tests, end-to-end tests, performance tests, security tests, and contract tests.
- Multi-layer Testing Strategy: Unit, Integration, and E2E tests
- Performance Testing: Load testing, stress testing, and performance monitoring
- Security Testing: Vulnerability scanning, authentication testing, and security headers validation
- Contract Testing: Service integration testing and API contract verification
- Test Data Management: Automated test data generation and cleanup
- Comprehensive Reporting: HTML, JSON, and JUnit format reports
- CI/CD Integration: Ready for continuous integration pipelines
npm installCreate a .env file with the following variables:
API_BASE_URL=http://localhost:3000
DATABASE_URL=postgresql://test:test@localhost:5432/nepa_test
REDIS_HOST=localhost
REDIS_PORT=6379
REDIS_PASSWORD=
API_TOKEN=
USER_SERVICE_URL=http://localhost:3001
NOTIFICATION_SERVICE_URL=http://localhost:3002
DOCUMENT_SERVICE_URL=http://localhost:3003
UTILITY_SERVICE_URL=http://localhost:3004
PAYMENT_SERVICE_URL=http://localhost:3005
BILLING_SERVICE_URL=http://localhost:3006
ANALYTICS_SERVICE_URL=http://localhost:3007
WEBHOOK_SERVICE_URL=http://localhost:3008npm run test:all# Unit tests
npm run test:unit
# Integration tests
npm run test:integration
# End-to-end tests
npm run test:e2e
# Performance tests
npm run test:performance
# Security tests
npm run test:security
# Contract tests
npm run test:contract
# Load tests (requires k6)
npm run test:load# Run all tests with health check
npm run test:api-health
# Verify contracts
npm run test:contract-verify
# Security scan
npm run test:security-scan
# Generate test report
npm run test:generate-reportapi-testing/
├── src/
│ ├── client/ # HTTP client for API requests
│ ├── contract/ # Contract testing
│ ├── data/ # Test data generation
│ ├── performance/ # Performance testing
│ ├── reporting/ # Test reporting
│ ├── security/ # Security testing
│ ├── services/ # Service-specific tests
│ └── types/ # TypeScript type definitions
├── tests/
│ ├── e2e/ # End-to-end tests
│ ├── integration/ # Integration tests
│ ├── load/ # Load testing scripts
│ └── unit/ # Unit tests
├── scripts/ # Utility scripts
└── contracts/ # Contract definitions
Test reports are generated in the test-reports/ directory:
- HTML Report: Interactive visual report
- JSON Report: Machine-readable format
- JUnit Report: CI/CD integration format
Performance tests include:
- Response time analysis
- Concurrent user testing
- Load balancing verification
- Database performance testing
- Memory usage monitoring
- Stress testing
Security tests cover:
- SQL injection vulnerability scanning
- XSS vulnerability detection
- Authentication bypass testing
- Rate limiting verification
- Security headers validation
- Input validation testing
Contract testing ensures:
- API response structure consistency
- Service integration compatibility
- Consumer-provider contract verification
- Breaking change detection
Add to your CI pipeline:
- name: Run API Tests
run: |
npm install
npm run test:ci- Node.js 18+
- PostgreSQL
- Redis
- K6 (for load testing)
- Add new tests to appropriate directories
- Follow naming conventions
- Update documentation
- Run full test suite before submitting
- Database Connection: Ensure PostgreSQL is running and configured
- API Health: Verify API server is accessible
- Authentication: Check API tokens and credentials
- Dependencies: Install all required packages
Enable debug logging:
DEBUG=* npm run test:allThe framework tracks:
- Test execution time
- Success/failure rates
- Performance metrics
- Security vulnerabilities
- Contract violations
- Run tests in isolated environments
- Use consistent test data
- Clean up after each test
- Monitor test performance
- Regular security scans
- Keep contracts updated
For issues and questions, please refer to the project documentation or create an issue in the repository.