Testing Workflow
Overview
Section titled “Overview”Comprehensive testing strategies using AI assistance for unit tests, integration tests, end-to-end tests, performance testing, and test automation across different frameworks and languages.
Prerequisites
Section titled “Prerequisites”- Rawi configured with a suitable provider
- Testing framework setup (Jest, Mocha, Pytest, etc.)
- Project codebase to test
- Basic understanding of testing principles
Workflow Steps
Section titled “Workflow Steps”1. Test Planning and Strategy
Section titled “1. Test Planning and Strategy”Plan comprehensive testing approach:
# Generate test strategyrawi ask --act test-engineer "Create a comprehensive testing strategy for a Node.js e-commerce API including unit, integration, and e2e tests"
# Test case generationrawi ask --file src/components/UserProfile.tsx --act test-engineer "Generate comprehensive test cases for this React component"
# Test pyramid analysisrawi ask --batch "src/**/*.js" --act test-engineer "Analyze codebase and recommend optimal test pyramid strategy"
2. Unit Test Generation
Section titled “2. Unit Test Generation”Create comprehensive unit tests:
# Generate JavaScript/TypeScript unit testsrawi ask --file src/utils/validation.js --act test-engineer "Create comprehensive Jest unit tests with edge cases and mocks"
# Generate Python unit testsrawi ask --file src/models.py --act test-engineer "Create pytest unit tests with fixtures and parameterization"
# Generate React component testsrawi ask --file src/components/Button.tsx --act test-engineer "Create React Testing Library tests with accessibility checks"
2.1. Test Command Generation
Section titled “2.1. Test Command Generation”Generate and execute testing commands:
# Run specific test suitesrawi exec "run all unit tests for authentication module"rawi exec "run integration tests with coverage report"rawi exec "execute end-to-end tests in headless mode"
# Test setup and configurationrawi exec "install Jest and testing dependencies for React project"rawi exec "configure Cypress for e2e testing"rawi exec "set up test database for integration tests"
# Test execution with different configurationsrawi exec "run tests in watch mode for development"rawi exec "run tests with verbose output and coverage"rawi exec "execute tests in CI environment with XML output"
3. Integration Test Generation
Section titled “3. Integration Test Generation”Create integration test suites:
# API integration testsrawi ask --file src/routes/users.js --act test-engineer "Create supertest integration tests for these API endpoints"
# Database integration testsrawi ask --file src/models/User.js --act test-engineer "Create database integration tests with test data setup and cleanup"
# Service integration testsrawi ask --file src/services/emailService.js --act test-engineer "Create integration tests with external service mocking"
4. End-to-End Test Generation
Section titled “4. End-to-End Test Generation”Create comprehensive e2e test suites:
# Playwright e2e testsrawi ask --act test-engineer "Create Playwright e2e tests for user authentication flow including login, registration, and password reset"
# Cypress e2e testsrawi ask --act test-engineer "Create Cypress e2e tests for e-commerce checkout flow with payment processing"
# Selenium testsrawi ask --act test-engineer "Create Selenium WebDriver tests for cross-browser compatibility testing"
Testing Best Practices
Section titled “Testing Best Practices”1. Test Structure
Section titled “1. Test Structure”- Follow AAA pattern (Arrange, Act, Assert)
- Use descriptive test names
- Keep tests independent and isolated
- Use proper test data management
- Implement proper setup and teardown
2. Test Coverage
Section titled “2. Test Coverage”- Aim for high code coverage (80%+)
- Focus on critical business logic
- Test edge cases and error conditions
- Include positive and negative scenarios
- Test performance requirements
3. Test Maintenance
Section titled “3. Test Maintenance”- Keep tests simple and focused
- Update tests with code changes
- Remove obsolete tests
- Refactor duplicate test code
- Document complex test scenarios
4. Test Performance
Section titled “4. Test Performance”- Optimize test execution time
- Use parallel execution when possible
- Minimize external dependencies
- Use efficient test data
- Monitor test suite performance
CI/CD Integration
Section titled “CI/CD Integration”GitHub Actions Testing Workflow
Section titled “GitHub Actions Testing Workflow”name: Comprehensive Testing
on: push: branches: [main, develop] pull_request:
jobs: unit-tests: runs-on: ubuntu-latest strategy: matrix: node-version: [16, 18, 20] steps: - uses: actions/checkout@v3 - name: Setup Node.js ${{ matrix.node-version }} uses: actions/setup-node@v3 with: node-version: ${{ matrix.node-version }} cache: 'npm' - run: npm ci - run: npm run test:unit - run: npm run test:coverage
integration-tests: runs-on: ubuntu-latest services: postgres: image: postgres:14 env: POSTGRES_PASSWORD: postgres options: >- --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 steps: - uses: actions/checkout@v3 - name: Setup Node.js uses: actions/setup-node@v3 with: node-version: '18' cache: 'npm' - run: npm ci - run: npm run test:integration env: DATABASE_URL: postgres://postgres:postgres@localhost:5432/test
e2e-tests: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - name: Setup Node.js uses: actions/setup-node@v3 with: node-version: '18' cache: 'npm' - run: npm ci - run: npx playwright install - run: npm run build - run: npm run test:e2e
performance-tests: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - name: Setup Node.js uses: actions/setup-node@v3 with: node-version: '18' cache: 'npm' - run: npm ci - run: npm run test:performance - name: Upload performance results uses: actions/upload-artifact@v3 with: name: performance-results path: performance-results/
security-tests: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - name: Setup Node.js uses: actions/setup-node@v3 with: node-version: '18' cache: 'npm' - run: npm ci - run: npm audit - run: npm run test:security