Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Instrumentation tests fix #347

Merged
merged 16 commits into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 56 additions & 6 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,13 @@ jobs:
- name: Build project
run: ./gradlew sdk:build -x test

unit-test-maven-publish:
name: Unit test and Publish Maven package
runs-on: ubuntu-latest
unit-intrumented-test-maven-publish:
name: Unit/Instrumented tests with coverage report
runs-on: ubuntu-22.04
timeout-minutes: 60
strategy:
matrix:
api-level: [ 29 ]
needs: build
steps:
- name: Checkout code
Expand All @@ -50,6 +54,12 @@ jobs:
distribution: 'zulu'
java-version: '17'

- name: Enable KVM group perms
run: |
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
sudo udevadm control --reload-rules
sudo udevadm trigger --name-match=kvm

- name: Cache Gradle dependencies
uses: actions/cache@v3
with:
Expand All @@ -60,9 +70,49 @@ jobs:
restore-keys: |
${{ runner.os }}-gradle-

- name: Run unit tests
# Switch to jacocoTestReport when instrumentation flakiness is fixed
run: ./gradlew sdk:jacocoUnitTestReport
- name: Determine emulator target
id: determine-target
run: |
TARGET="google_apis"
if [[ ${{ matrix.api-level }} -ge 34 ]]; then
TARGET="aosp_atd"
fi
echo "TARGET=$TARGET" >> $GITHUB_OUTPUT

- name: AVD cache
uses: actions/cache@v3
id: avd-cache
with:
path: |
~/.android/avd/*
~/.android/adb*
key: avd-${{ matrix.api-level }}

- name: Create AVD and generate snapshot for caching
if: steps.avd-cache.outputs.cache-hit != 'true'
uses: reactivecircus/android-emulator-runner@v2
with:
api-level: ${{ matrix.api-level }}
target: ${{ steps.determine-target.outputs.TARGET }}
arch: x86_64
force-avd-creation: false
emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
disable-animations: true
script: echo "Generated AVD snapshot for caching."

- name: Run unit/instrumented tests
uses: reactivecircus/android-emulator-runner@v2
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
with:
api-level: ${{ matrix.api-level }}
target: ${{ steps.determine-target.outputs.TARGET }}
arch: x86_64
force-avd-creation: false
emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
disable-animations: true
profile: Nexus One
script: ./gradlew sdk:jacocoTestReport

- name: Publish Maven package
run: ./gradlew sdk:publish
Expand Down
60 changes: 54 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,13 @@ jobs:
- name: Build project
run: ./gradlew sdk:build -x test

unit-test:
name: Unit tests with coverage report
runs-on: ubuntu-latest
unit-intrumented-test:
name: Unit/Instrumented tests with coverage report
runs-on: ubuntu-22.04
timeout-minutes: 60
strategy:
matrix:
api-level: [ 29 ]
needs: build
steps:
- name: Checkout code
Expand All @@ -50,6 +54,12 @@ jobs:
distribution: 'zulu'
java-version: '17'

- name: Enable KVM group perms
run: |
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
sudo udevadm control --reload-rules
sudo udevadm trigger --name-match=kvm

- name: Cache Gradle dependencies
uses: actions/cache@v3
with:
Expand All @@ -60,9 +70,47 @@ jobs:
restore-keys: |
${{ runner.os }}-gradle-

- name: Run unit tests
- name: Determine emulator target
id: determine-target
run: |
TARGET="google_apis"
if [[ ${{ matrix.api-level }} -ge 34 ]]; then
TARGET="aosp_atd"
fi
echo "TARGET=$TARGET" >> $GITHUB_OUTPUT

- name: AVD cache
uses: actions/cache@v3
id: avd-cache
with:
path: |
~/.android/avd/*
~/.android/adb*
key: avd-${{ matrix.api-level }}

- name: Create AVD and generate snapshot for caching
if: steps.avd-cache.outputs.cache-hit != 'true'
uses: reactivecircus/android-emulator-runner@v2
with:
api-level: ${{ matrix.api-level }}
target: ${{ steps.determine-target.outputs.TARGET }}
arch: x86_64
force-avd-creation: false
emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
disable-animations: true
script: echo "Generated AVD snapshot for caching."

- name: Run unit/instrumented tests
uses: reactivecircus/android-emulator-runner@v2
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
# Switch to jacocoTestReport when instrumentation flakiness is fixed
run: ./gradlew sdk:jacocoUnitTestReport sdk:sonar
with:
api-level: ${{ matrix.api-level }}
target: ${{ steps.determine-target.outputs.TARGET }}
arch: x86_64
force-avd-creation: false
emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
disable-animations: true
profile: Nexus One
script: ./gradlew sdk:jacocoTestReport sdk:sonar

14 changes: 1 addition & 13 deletions sdk/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -86,17 +86,6 @@ android {
// issue with agp > 8 so we had to add this line https://github.com/Kotlin/kotlinx.serialization/issues/2145
freeCompilerArgs = ["-Xstring-concat=inline"]
}
android {
sourceSets {
String sharedTestDir = "$projectDir/src/sharedTest/java"
test {
java.srcDir sharedTestDir
}
androidTest {
java.srcDir sharedTestDir
}
}
}
}

publishing {
Expand Down Expand Up @@ -296,8 +285,7 @@ sonar {
property 'sonar.organization', 'omise'
property 'sonar.projectName', 'omise-android'
property 'sonar.projectKey', 'omise_omise-android'
// TODO: Change to the correct path once the instrumentation tests are not flaky
property 'sonar.coverage.jacoco.xmlReportPaths', "${project.buildDir}/reports/jacoco/jacocoUnitTestReport/jacocoUnitTestReport.xml"
property 'sonar.coverage.jacoco.xmlReportPaths', "${project.buildDir}/reports/jacoco/jacocoTestReport/jacocoTestReport.xml"
property 'sonar.junit.reportPaths', "${project.buildDir}/test-results/testProductionDebugUnitTest"
property 'sonar.androidLint.reportPaths', "${project.buildDir}/reports/lint-results-productionDebug.xml"
}
Expand Down
8 changes: 4 additions & 4 deletions sdk/src/androidTest/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@

<application>
<activity
android:name=".ui.AuthorizingPaymentActivity"
android:name="co.omise.android.ui.AuthorizingPaymentActivity"
android:theme="@style/OmiseTheme" />
<activity
android:name=".ui.CreditCardActivity"
android:name="co.omise.android.ui.CreditCardActivity"
android:theme="@style/OmiseTheme" />
<activity
android:name=".ui.PaymentCreatorActivity"
android:name="co.omise.android.ui.PaymentCreatorActivity"
android:theme="@style/OmiseTheme" />
<activity
android:name=".ui.TestFragmentActivity"
android:name="co.omise.android.ui.TestFragmentActivity"
android:theme="@style/OmiseTheme" />
</application>
</manifest>
Loading
Loading