Skip to content

Commit

Permalink
Instrumentation tests fix (#347)
Browse files Browse the repository at this point in the history
* Fix instrumented tests

* Update CI to include instrumented tests

* Change uses to script

* Add api-level to CI/CD

* Set api level to 29

* Change target arch to arm64-v8a

* Update CI/CD based on docs

* Add scroll to position to avoid flaky test (trial)

* Set report to new path including instrumented tests

* Fix job name

* Add terminate crashpad to CI

* Set terminate crashpad to inline script

* Move comment

* Add sleep to wait for emulator to shutdown

* Change api level to 33 and ubuntu-latest

* Change job name
  • Loading branch information
AnasNaouchi authored May 31, 2024
1 parent f4d9021 commit 957cfeb
Show file tree
Hide file tree
Showing 25 changed files with 265 additions and 72 deletions.
60 changes: 55 additions & 5 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
unit-intrumented-test-maven-publish:
name: Unit/Instrumented tests with maven publish
runs-on: ubuntu-latest
timeout-minutes: 60
strategy:
matrix:
api-level: [ 33 ]
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
58 changes: 53 additions & 5 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
unit-intrumented-test:
name: Unit/Instrumented tests with coverage report
runs-on: ubuntu-latest
timeout-minutes: 60
strategy:
matrix:
api-level: [ 33 ]
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

0 comments on commit 957cfeb

Please sign in to comment.