Skip to content

add: unit test (Cursor) #2

add: unit test (Cursor)

add: unit test (Cursor) #2

Workflow file for this run

name: Android CI/CD
on:
push:
branches: [ master, develop ]
pull_request:
branches: [ master, develop ]
jobs:
test:
runs-on: ubuntu-latest
name: Unit Tests
steps:
- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
- name: Cache Gradle packages
uses: actions/cache@v3
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Run MVVM Unit Tests
run: ./gradlew :mvvm:testDebugUnitTest
- name: Run App Unit Tests
run: ./gradlew :app:testDebugUnitTest
- name: Generate Code Coverage Report
run: |
./gradlew :mvvm:jacocoTestReport
./gradlew :app:jacocoTestReport
- name: Upload Unit Test Results
uses: actions/upload-artifact@v3
if: always()
with:
name: unit-test-results
path: |
app/build/test-results/testDebugUnitTest/
mvvm/build/test-results/testDebugUnitTest/
- name: Upload Coverage Reports
uses: actions/upload-artifact@v3
if: always()
with:
name: coverage-reports
path: |
app/build/reports/jacoco/
mvvm/build/reports/jacoco/
- name: Comment Test Results
uses: EnricoMi/publish-unit-test-result-action@v2
if: always()
with:
files: |
app/build/test-results/testDebugUnitTest/TEST-*.xml
mvvm/build/test-results/testDebugUnitTest/TEST-*.xml
build:
runs-on: ubuntu-latest
needs: test
name: Build
steps:
- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
- name: Cache Gradle packages
uses: actions/cache@v3
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Build Debug APK
run: ./gradlew :app:assembleDebug
- name: Build MVVM Library
run: ./gradlew :mvvm:assembleDebug
- name: Upload Debug APK
uses: actions/upload-artifact@v3
with:
name: debug-apk
path: app/build/outputs/apk/debug/*.apk
- name: Upload MVVM Library
uses: actions/upload-artifact@v3
with:
name: mvvm-library
path: mvvm/build/outputs/aar/*.aar
publish-test-results:
runs-on: ubuntu-latest
needs: test
if: always()
steps:
- name: Download Test Results
uses: actions/download-artifact@v3
with:
name: unit-test-results
path: test-results/
- name: Publish Test Results Summary
run: |
echo "## 🧪 Unit Test Results Summary" >> $GITHUB_STEP_SUMMARY
echo "| Module | Test Files | Status |" >> $GITHUB_STEP_SUMMARY
echo "|--------|------------|---------|" >> $GITHUB_STEP_SUMMARY
# Count test files
app_tests=$(find test-results -name "TEST-*.xml" -path "*/app/*" 2>/dev/null | wc -l)
mvvm_tests=$(find test-results -name "TEST-*.xml" -path "*/mvvm/*" 2>/dev/null | wc -l)
echo "| App Module | $app_tests | ✅ |" >> $GITHUB_STEP_SUMMARY
echo "| MVVM Module | $mvvm_tests | ✅ |" >> $GITHUB_STEP_SUMMARY
echo "| **Total** | **$((app_tests + mvvm_tests))** | **✅** |" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### 📊 Test Coverage Available" >> $GITHUB_STEP_SUMMARY
echo "- Code coverage reports generated with Jacoco" >> $GITHUB_STEP_SUMMARY
echo "- Coverage reports available in artifacts" >> $GITHUB_STEP_SUMMARY
echo "- Unit tests cover all major MVVM components" >> $GITHUB_STEP_SUMMARY