38AutomationAutomationCI/CD
How do you integrate automated tests with CI/CD pipelines?
CI/CD integration allows automated tests to run automatically on code changes, providing fast feedback and ensuring quality before deployment.
Common CI/CD Tools
- Jenkins
- GitHub Actions
- GitLab CI/CD
- Azure DevOps
- CircleCI
- Travis CI
GitHub Actions Example
name: Run Tests
on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main ]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.9'
- name: Install dependencies
run: |
pip install -r requirements.txt
- name: Run tests
run: |
pytest tests/ --html=report.html
- name: Upload test results
if: always()
uses: actions/upload-artifact@v2
with:
name: test-results
path: report.html
Jenkins Pipeline Example
pipeline {
agent any
stages {
stage('Checkout') {
steps {
git 'https://github.com/your-repo.git'
}
}
stage('Install Dependencies') {
steps {
sh 'npm install'
}
}
stage('Run Tests') {
steps {
sh 'npm test'
}
}
stage('Generate Report') {
steps {
publishHTML([reportDir: 'reports', reportFiles: 'index.html'])
}
}
}
post {
always {
junit 'test-results/*.xml'
}
}
}
Best Practices
- Run tests on every commit/pull request
- Separate test suites (smoke, regression, full)
- Run critical tests first for fast feedback
- Generate and archive test reports
- Send notifications on test failures
- Use parallel execution to reduce time
- Maintain test environment consistency
Benefits
- Early bug detection
- Faster feedback to developers
- Automated quality gates
- Reduced manual testing effort
- Consistent test execution