Return to site

🚦🧪 RUN TESTS IN PARALLEL IN GITHUB ACTIONS WITH A MATRIX

· testing

🔸 TLDR

▪️ A GitHub Actions matrix lets you run the same test job multiple times in parallel (e.g., mysql + mssql) for faster CI and better coverage ⚡✅

Section image

🔸 CONTEXT

You don’t need “parallel Maven tests” to speed up CI. Often the biggest win is running the same test suite against multiple environments (DBs, JDKs, configs…) in parallel using a GitHub Actions matrix. ⚡

🔸 THE IDEA

Use a strategy.matrix to spawn multiple runners—one per configuration—and keep the workflow readable and scalable.

integration-tests:
 needs: build
 runs-on: ubuntu-latest
 continue-on-error: true
 strategy:
 matrix:
 profile: [ mysql, mssql ]
 steps:
 - name: Checkout Code
 uses: actions/checkout@v4
 - name: Set up JDK 25
 uses: actions/setup-java@v5
 with:
 java-version: '25'
 distribution: 'temurin'
 - name: Run Database Tests with Profile ${{ matrix.profile }}
 run: mvn test -Dtest=PaymentIntegrationTest -P${{ matrix.profile }}

🔸 WHY THIS IS POWERFUL

▪️ Faster feedback: DB profiles run at the same time ⏱️

▪️ Higher confidence: you validate behavior across environments ✅

▪️ Easy to extend: add postgres, add another JDK, add another OS—same pattern 🧩

🔸 PRACTICAL TIPS

▪️ Split “build” and “integration-tests” (needs: build) so you compile once, then fan out 🧱➡️🧪

▪️ Use Maven profiles (-P...) to switch DB drivers, URLs, containers, Flyway/Liquibase config 🛠️

▪️ Prefer targeted tests (like -Dtest=PaymentIntegrationTest) to keep CI tight 🎯

▪️ If you want strict CI: remove continue-on-error: true (or keep it temporarily while onboarding new DBs) 🚨

🔸 TAKEAWAYS

▪️ Use strategy.matrix for cross-environment confidence, not just speed 🧠

▪️ Combine matrix + Maven profiles to keep pipeline logic clean 🧼

▪️ Start small (2 DBs), then scale safely by adding one axis at a time 📈

#GitHubActions #CI #DevOps #Testing #IntegrationTesting #Java #Maven #Automation #QualityEngineering #SoftwareEngineering

Go further with Java certification:

Java👇

Spring👇

SpringBook👇

JavaBook👇