Jenkins is a powerful open-source automation server that enables continuous integration and...
How to Automate API Testing in CI/CD Using GitHub Actions + Bruno
Continuous Integration and Continuous Delivery (CI/CD) has become essential for modern software development teams. When it comes to API testing automation, GitHub Actions stands out as a powerful platform that seamlessly integrates with your existing GitHub workflow.
Bruno CLI takes this integration to the next level by providing a robust command-line interface that works perfectly within GitHub Actions workflows. No more manual API testing or complex setup processesβjust automated, reliable API testing that runs with every code push.
Prerequisites
Before setting up GitHub Actions with Bruno CLI, ensure you have:
- A GitHub repository containing your Bruno collections
- Basic understanding of GitHub Actions workflows
π Organizing Your Bruno Collections
Proper organization is key to successful CI/CD integration. Here's the recommended structure for your repository:
your-api-project/
βββ .github/
β βββ workflows/
β βββ api-tests.yml
βββ collections/
β βββ authentication/
β β βββ login.bru
β β βββ logout.bru
βββ environments/
β βββ development.bru
β βββ ci.bru
β βββ production.bru
βββ bruno.json
Key points:
.github/workflows/
- Contains your GitHub Actions workflow filescollections/
- Your Bruno API collections organized by featureenvironments/
- Environment-specific configuration filesci.bru
- Environment file for CI/CD testing
βοΈ Creating Your GitHub Actions Workflow
Create a new file at .github/workflows/api-tests.yml
in your repository. This workflow will automatically run your API tests on every push and pull request.
name: API Tests
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Install Bruno CLI
run: npm install -g @usebruno/cli
- name: Run API Tests
run: bru run --env ci --reporter-html results.html
- name: Upload Test Results
uses: actions/upload-artifact@v4
with:
name: test-results
path: results.html
What this workflow does:
- Triggers: Runs on pushes to main branch and pull requests
- Environment: Uses Ubuntu latest runner
- Setup: Checks out code and installs Node.js 20
- Installation: Installs Bruno CLI globally
- Testing: Runs API tests with CI environment and generates HTML report
- Artifacts: Uploads test results for later analysis
π Security and Environment Variables
For secure API testing, use GitHub's encrypted secrets to store sensitive data:
- name: Run API Tests with Secrets
run: |
bru run --env ci \
--env-var API_KEY=$ \
--env-var JWT_TOKEN=$
env:
API_BASE_URL: $
Setting up secrets:
- Go to your GitHub repository
- Navigate to Settings β Secrets and variables β Actions
- Click New repository secret
- Add your sensitive data (API keys, tokens, etc.)
π Monitoring and Troubleshooting
Monitor your API testing workflows effectively:
Workflow Status
- Check the Actions tab in your GitHub repository
- Monitor build status and execution time
- Review logs for any failures or issues
Test Results Analysis
- Download artifacts from successful builds
- Analyze HTML reports test-results.html for detailed test results
- Use JUnit reports for integration with other tools
π Try the Demo Yourself
Weβve published the full working collection on GitHub. You can either clone this, or simply click the Fetch in Bruno button below!
π Final Thoughts
GitHub Actions integration with Bruno CLI provides a powerful, automated solution for API testing. By following the patterns and best practices outlined in this guide, you can create reliable, maintainable CI/CD pipelines that ensure your APIs remain stable and functional.
Ready to automate your API testing? Start with the basic workflow and gradually add advanced features as your needs grow.
Happy testing! π