Skip to content

improve and enhance test coverage #17

improve and enhance test coverage

improve and enhance test coverage #17

Workflow file for this run

name: Java SDK - Coverage Check
on:
pull_request:
branches:
- development
- staging
- master
jobs:
coverage:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up JDK 8 (Temurin)
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '8'
cache: maven
- name: Enable tests in pom.xml
run: |
echo "πŸ”§ Ensuring tests are enabled in pom.xml..."
sed -i 's/<skipTests>true<\/skipTests>/<skipTests>false<\/skipTests>/g' pom.xml || true
- name: Run tests and generate JaCoCo report
run: mvn clean test -Dtest='Test*' jacoco:report -Dgpg.skip=true
- name: πŸ“Š Extract coverage from JaCoCo HTML report
id: extract_coverage
run: |
echo "Extracting coverage summary from JaCoCo HTML report..."
if [ ! -f target/site/jacoco/index.html ]; then
echo "❌ JaCoCo HTML report not found!"
exit 1
fi
# Extract coverage percentages using awk for more reliable extraction
COVERAGE_VALUES=$(grep -A10 '<td>Total</td>' target/site/jacoco/index.html | grep -E 'class="ctr2".*[0-9]+%' | sed -E 's/.*>([0-9]+)%<.*/\1/')
echo "Debug: All coverage values found:"
echo "$COVERAGE_VALUES"
INSTRUCTION=$(echo "$COVERAGE_VALUES" | awk 'NR==1')
BRANCH=$(echo "$COVERAGE_VALUES" | awk 'NR==2')
echo "πŸ“˜ Instruction Coverage: ${INSTRUCTION:-0}%"
echo "🌿 Branch Coverage: ${BRANCH:-0}%"
echo "instruction=${INSTRUCTION:-0}" >> $GITHUB_OUTPUT
echo "branch=${BRANCH:-0}" >> $GITHUB_OUTPUT
- name: πŸ’¬ Post coverage summary as PR comment
uses: marocchino/sticky-pull-request-comment@v2
with:
header: πŸ§ͺ JaCoCo Coverage Report
message: |
**Coverage Summary**
- πŸ“˜ Instruction Coverage: `${{ steps.extract_coverage.outputs.instruction }}%`
- 🌿 Branch Coverage: `${{ steps.extract_coverage.outputs.branch }}%`
- name: πŸ“¦ Upload JaCoCo HTML report as artifact
uses: actions/upload-artifact@v4
with:
name: jacoco-report
path: target/site/jacoco/
if-no-files-found: warn