To ensure that all your Java 21 + Spring Boot + Apache Camel 4 Maven modules pass their unit tests locally, just like in GitHub CI, you can follow these steps:
✅ Goal:
Run all the unit tests across your multi-module Maven project locally and verify they all pass — just like in GitHub.
🛠️ Steps to Check Unit Tests Locally
1. Ensure You're on the Right Branch
Make sure your local branch is up-to-date with the one being tested in GitHub (e.g., main, develop):
git checkout main
git pull origin main
2. Clean & Install All Modules
From the root of your Maven project, run:
mvn clean install
This will:
- Compile all modules.
- Run all unit tests.
- Package JARs/WARs.
- Install them into your local Maven repository.
If any test fails, Maven will show the error and fail the build by default.
💡 Tip: Use -DskipTests if you want to skip tests temporarily.
3. See Detailed Test Output (Optional)
If a test fails and you need more info:
mvn test
You can then look at the specific test output in:
<module>/target/surefire-reports/*.txt
Or for failing tests only:
find . -name "*.txt" -exec grep -l "FAIL" {} \;
4. Run Specific Failing Module(s) Only
If you know which module is failing:
cd path/to/module
mvn test
This helps isolate and debug the issue quickly.
5. Check Environment Differences
Sometimes tests pass in CI but not locally due to environment differences.
Ensure:
- Same Java version:
java --version should be Java 21.
- Same Spring Boot / Camel versions in
pom.xml.
- Any required environment variables, config files, or mocks are set up.
- If tests use Docker (e.g., via Testcontainers), make sure Docker is running.
6. Enable Debug Logging (Optional)
Add this to application.properties or logback-spring.xml if needed:
logging.level.org.springframework=DEBUG
logging.level.org.apache.camel=DEBUG
Or enable logging in test classes directly.
7. Use an IDE (IntelliJ/Eclipse)
IDEs often help re-run failed tests with debugging enabled:
- Right-click > Run/Debug failed test class/method.
- Set breakpoints.
- Inspect variables.
🧪 Bonus: Replicate CI Environment Exactly
If you're using GitHub Actions, look at your .github/workflows/ci.yml.
Example snippet:
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up JDK 21
uses: actions/setup-java@v3
with:
java-version: '21'
distribution: 'temurin'
- name: Build with Maven
run: mvn clean install
To simulate this locally:
- Use SDKMAN! or
jenv to switch to Java 21.
- Use same OS or containerized setup (e.g., Docker).
🧹 Optional: Clean Local Maven Cache
Sometimes corrupted dependencies cause flaky test behavior:
rm -rf ~/.m2/repository/<your-group-id>
mvn install
✅ Summary Checklist
| Step | Action |
|---|
| ✔️ | git pull latest code |
| ✔️ | Run mvn clean install from root |
| ✔️ | Investigate failed tests in surefire-reports |
| ✔️ | Match Java version (Java 21) |
| ✔️ | Check for env differences (DB, Docker, etc.) |
| ✔️ | Use IDE for debugging |
| ✔️ | Compare with GitHub Actions config |
Let me know if you'd like help interpreting a specific test failure or how to debug it further.