Skip to content

improve and enhance test coverage #6

improve and enhance test coverage

improve and enhance test coverage #6

Workflow file for this run

name: Java SDK - Coverage Check
on:
pull_request:
branches:
- development
- staging
- master
jobs:
test-and-coverage:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '17'
cache: maven
- name: Run Tests and Generate JaCoCo Report
working-directory: contentstack-java
run: mvn clean test -Dtest='Test*' jacoco:report -Dgpg.skip=true
- name: Verify Coverage Thresholds
working-directory: contentstack-java
run: |
echo "Checking JaCoCo coverage thresholds..."
INSTRUCTION_COVERAGE=$(grep -oPm1 "(?<=<counter type=\"INSTRUCTION\" missed=\")\d+\" covered=\"\d+\"" target/site/jacoco/jacoco.xml | sed 's/" covered="/ /' | awk '{print $2/($1+$2)*100}')
BRANCH_COVERAGE=$(grep -oPm1 "(?<=<counter type=\"BRANCH\" missed=\")\d+\" covered=\"\d+\"" target/site/jacoco/jacoco.xml | sed 's/" covered="/ /' | awk '{print $2/($1+$2)*100}')
echo "Instruction Coverage: $INSTRUCTION_COVERAGE%"
echo "Branch Coverage: $BRANCH_COVERAGE%"
MIN_INSTRUCTION=90
MIN_BRANCH=80
if (( ${INSTRUCTION_COVERAGE%.*} < MIN_INSTRUCTION )); then
echo "❌ Instruction coverage below $MIN_INSTRUCTION%"
exit 1
fi
if (( ${BRANCH_COVERAGE%.*} < MIN_BRANCH )); then
echo "❌ Branch coverage below $MIN_BRANCH%"
exit 1
fi
echo "✅ Coverage thresholds met."
- name: Upload JaCoCo HTML Report (Artifact)
uses: actions/upload-artifact@v4
with:
name: jacoco-report
path: contentstack-java/target/site/jacoco/