Skip to content

Commit c6cc34b

Browse files
Enhance unit testing workflow: enable tests in pom.xml temporarily, improve JaCoCo coverage checks with XML report validation, and ensure consistent execution of coverage summary and report upload steps.
1 parent 3714a2b commit c6cc34b

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

.github/workflows/unit-testing.yml

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,23 @@ jobs:
1818
- name: Checkout Repository
1919
uses: actions/checkout@v4
2020

21-
- name: Set up JDK 8
21+
- name: Set up JDK 8 (Temurin)
2222
uses: actions/setup-java@v4
2323
with:
2424
distribution: 'temurin'
2525
java-version: '8'
2626
cache: maven
2727

28+
- name: Ensure Tests Are Enabled in pom.xml
29+
run: |
30+
echo "🔧 Temporarily enabling tests in pom.xml..."
31+
if [[ "$OSTYPE" == "darwin"* ]]; then
32+
sed -i '' 's/<skipTests>true<\/skipTests>/<skipTests>false<\/skipTests>/g' pom.xml || true
33+
else
34+
sed -i 's/<skipTests>true<\/skipTests>/<skipTests>false<\/skipTests>/g' pom.xml || true
35+
fi
36+
echo "✅ Tests enabled."
37+
2838
- name: Run Tests and Generate JaCoCo Report
2939
run: mvn clean test -Dtest='Test*' jacoco:report -Dgpg.skip=true
3040

@@ -33,9 +43,13 @@ jobs:
3343
run: |
3444
echo "Checking JaCoCo coverage thresholds..."
3545
36-
# Extract coverage values from XML
37-
INSTRUCTION=$(grep -oPm1 '(?<=<counter type="INSTRUCTION" missed=")[0-9]+" covered="[0-9]+"' target/site/jacoco/jacoco.xml | sed 's/" covered="/ /' | awk '{print $2/($1+$2)*100}')
38-
BRANCH=$(grep -oPm1 '(?<=<counter type="BRANCH" missed=")[0-9]+" covered="[0-9]+"' target/site/jacoco/jacoco.xml | sed 's/" covered="/ /' | awk '{print $2/($1+$2)*100}')
46+
if [ ! -f target/site/jacoco/jacoco.xml ]; then
47+
echo "❌ JaCoCo XML report not found."
48+
exit 1
49+
fi
50+
51+
INSTRUCTION=$(grep -oPm1 '(?<=<counter type="INSTRUCTION" missed=")[0-9]+" covered="[0-9]+"' target/site/jacoco/jacoco.xml | sed 's/" covered="/ /' | awk '{printf "%.2f", ($2/($1+$2))*100}')
52+
BRANCH=$(grep -oPm1 '(?<=<counter type="BRANCH" missed=")[0-9]+" covered="[0-9]+"' target/site/jacoco/jacoco.xml | sed 's/" covered="/ /' | awk '{printf "%.2f", ($2/($1+$2))*100}')
3953
4054
echo "Instruction Coverage: $INSTRUCTION%"
4155
echo "Branch Coverage: $BRANCH%"
@@ -59,6 +73,7 @@ jobs:
5973
echo "✅ Coverage thresholds met."
6074
6175
- name: Comment Coverage Summary on PR
76+
if: always()
6277
uses: marocchino/sticky-pull-request-comment@v2
6378
with:
6479
header: "🧪 JaCoCo Coverage Report"
@@ -70,6 +85,7 @@ jobs:
7085
✅ Minimum thresholds: 90% instruction, 80% branch
7186
7287
- name: Upload JaCoCo HTML Report
88+
if: always()
7389
uses: actions/upload-artifact@v4
7490
with:
7591
name: jacoco-report

0 commit comments

Comments
 (0)