Skip to content

Commit

Permalink
Merge pull request #1561 from Adyen/setup-ui-testing
Browse files Browse the repository at this point in the history
Setup UI testing
  • Loading branch information
OscarSpruit authored May 1, 2024
2 parents c58a06e + a9045c7 commit b937ea4
Show file tree
Hide file tree
Showing 19 changed files with 441 additions and 36 deletions.
12 changes: 5 additions & 7 deletions .github/workflows/assemble.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,14 @@ jobs:
with:
distribution: 'zulu'
java-version: 17
cache: 'gradle'

- name: Gradle cache
uses: gradle/actions/setup-gradle@v3
with:
cache-read-only: false

- name: Grant execute permission for gradlew
run: chmod +x gradlew

- name: Run assembleDebug
run: ./gradlew assDeb --no-daemon

- name: Cache build output
uses: actions/cache/save@v3
with:
path: /home/runner/work/adyen-android/adyen-android
key: cache-${{ github.run_id }}-${{ github.run_attempt }}
4 changes: 4 additions & 0 deletions .github/workflows/check_develop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ concurrency:
cancel-in-progress: true

jobs:
assemble:
name: Assemble
uses: ./.github/workflows/assemble.yml
sonar_cloud:
name: SonarCloud
uses: ./.github/workflows/sonar_cloud.yml
needs: assemble
secrets: inherit
6 changes: 5 additions & 1 deletion .github/workflows/check_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ jobs:
with:
distribution: 'zulu'
java-version: 17
cache: 'gradle'

- name: Gradle cache
uses: gradle/actions/setup-gradle@v3
with:
cache-read-only: true

- name: Grant execute permission for gradlew
run: chmod +x gradlew
Expand Down
12 changes: 10 additions & 2 deletions .github/workflows/code_analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ jobs:
with:
distribution: 'zulu'
java-version: 17
cache: 'gradle'

- name: Gradle cache
uses: gradle/actions/setup-gradle@v3
with:
cache-read-only: true

- name: Grant execute permission for gradlew
run: chmod +x gradlew
Expand All @@ -36,7 +40,11 @@ jobs:
with:
distribution: 'zulu'
java-version: 17
cache: 'gradle'

- name: Gradle cache
uses: gradle/actions/setup-gradle@v3
with:
cache-read-only: true

- name: Grant execute permission for gradlew
run: chmod +x gradlew
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/generate_dependency_graph.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ jobs:
with:
distribution: 'zulu'
java-version: 17
cache: 'gradle'

- name: Gradle cache
uses: gradle/actions/setup-gradle@v3
with:
cache-read-only: true

- name: Setup Graphviz
uses: ts-graphviz/setup-graphviz@v2
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/publish_docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ jobs:
with:
distribution: 'zulu'
java-version: 17
cache: 'gradle'

- name: Gradle cache
uses: gradle/actions/setup-gradle@v3
with:
cache-read-only: true

- name: Grant execute permission for gradlew
run: chmod +x gradlew
Expand Down
10 changes: 7 additions & 3 deletions .github/workflows/publish_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,15 @@ jobs:
with:
distribution: 'zulu'
java-version: 17
cache: 'gradle'


- name: Gradle cache
uses: gradle/actions/setup-gradle@v3
with:
cache-read-only: true

- name: Grant execute permission for gradlew
run: chmod +x gradlew

- name: Gradle check
run: ./gradlew check --no-daemon

Expand Down
14 changes: 6 additions & 8 deletions .github/workflows/run_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,11 @@ jobs:
with:
distribution: 'zulu'
java-version: 17
cache: 'gradle'

- uses: actions/cache/restore@v3
- name: Gradle cache
uses: gradle/actions/setup-gradle@v3
with:
path: /home/runner/work/adyen-android/adyen-android
key: cache-${{ github.run_id }}-${{ github.run_attempt }}
cache-read-only: false

- name: Grant execute permission for gradlew
run: chmod +x gradlew
Expand All @@ -41,12 +40,11 @@ jobs:
with:
distribution: 'zulu'
java-version: 17
cache: 'gradle'

- uses: actions/cache/restore@v3
- name: Gradle cache
uses: gradle/actions/setup-gradle@v3
with:
path: /home/runner/work/adyen-android/adyen-android
key: cache-${{ github.run_id }}-${{ github.run_attempt }}
cache-read-only: false

- name: Grant execute permission for gradlew
run: chmod +x gradlew
Expand Down
71 changes: 71 additions & 0 deletions .github/workflows/run_ui_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: UI Tests

on:
push:
branches:
- 'develop'
workflow_dispatch:

jobs:
ui-test:
name: Run UI tests
runs-on: ubuntu-latest
strategy:
matrix:
# Define the Android version you want to run UI tests for here.
api-level: [ 34 ]

steps:
- uses: actions/checkout@v4

- name: Enable KVM
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: Set up JDK
uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: 17

- name: Gradle cache
uses: gradle/actions/setup-gradle@v3
with:
cache-read-only: false

- name: AVD cache
uses: actions/cache@v4
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: google_apis
arch: x86_64
force-avd-creation: false
emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
disable-animations: false
script: echo "Generated AVD snapshot for caching."

- name: Run connectedDebugAndroidTest
uses: reactivecircus/android-emulator-runner@v2
env:
ADYEN_ANDROID_MERCHANT_SERVER_URL: 'https://android-ui-tests.adyen.com/'
ADYEN_ANDROID_CLIENT_KEY: 'test_fakefakefakefakefakefakefakefake'
with:
api-level: ${{ matrix.api-level }}
target: google_apis
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
script: ./gradlew connectedDebugAndroidTest
8 changes: 6 additions & 2 deletions .github/workflows/sonar_cloud.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,14 @@ jobs:
with:
distribution: 'zulu'
java-version: 17
cache: 'gradle'

- name: Gradle cache
uses: gradle/actions/setup-gradle@v3
with:
cache-read-only: true

- name: Cache SonarCloud packages
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/update_verification_metadata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ jobs:
with:
distribution: 'zulu'
java-version: 17
cache: 'gradle'

- name: Gradle cache
uses: gradle/actions/setup-gradle@v3
with:
cache-read-only: true

- name: Grant execute permission for gradlew
run: chmod +x gradlew
Expand Down
6 changes: 6 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ subprojects {
sourceCompatibility = javaVersion
targetCompatibility = javaVersion
}

packagingOptions {
excludes += "/META-INF/{AL2.0,LGPL2.1}"
merges += "META-INF/LICENSE.md"
merges += "META-INF/LICENSE-notice.md"
}
}
}

Expand Down
4 changes: 4 additions & 0 deletions dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ ext {

// Tests
arch_core_testing_version = "2.2.0"
barista_version = "4.2.0"
espresso_version = "3.5.1"
json_version = '20240303'
jose4j_version = '0.9.6'
Expand Down Expand Up @@ -144,11 +145,14 @@ ext {
androidx : [
lifecycle: "androidx.arch.core:core-testing:$arch_core_testing_version"
],
barista : "com.adevinta.android:barista:$barista_version",
espresso : [
"androidx.test.espresso:espresso-contrib:$espresso_version",
"androidx.test.espresso:espresso-core:$espresso_version",
"androidx.test.espresso:espresso-intents:$espresso_version"
],
hilt : "com.google.dagger:hilt-android-testing:$hilt_version",
hiltCompiler : "com.google.dagger:hilt-android-compiler:$hilt_version",
jose4j : "org.bitbucket.b_c:jose4j:$jose4j_version",
json : "org.json:json:$json_version",
junit5 : [
Expand Down
13 changes: 10 additions & 3 deletions example-app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ apply from: "${rootDir}/config/gradle/codeQuality.gradle"

if (file("local.gradle").exists()) {
apply from: "local.gradle"
} else if (System.getenv("CI") == "true") {
apply from: "ci.local.gradle"
} else if (!isIDEBuild()) {
// if not building from an IDE, use example file as it is to ensure the build passes (for CI, renovate, etc)
apply from: "example.local.gradle"
// Renovate doesn't set the CI variable, so this way we can still make sure the build succeeds.
apply from: "ci.local.gradle"
} else {
throw new GradleException("File example-app/local.gradle not found. Check example-app/README.md for more instructions.")
}
Expand All @@ -40,7 +42,7 @@ android {
versionCode version_code
versionName version_name

testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
testInstrumentationRunner 'com.adyen.checkout.HiltTestRunner'
}

testOptions {
Expand Down Expand Up @@ -105,6 +107,11 @@ dependencies {
// Tests
testImplementation testLibraries.junit5
testImplementation testLibraries.mockito

androidTestImplementation testLibraries.androidTest
androidTestImplementation testLibraries.barista
androidTestImplementation testLibraries.espresso
androidTestImplementation testLibraries.hilt

kaptAndroidTest testLibraries.hiltCompiler
}
24 changes: 24 additions & 0 deletions example-app/ci.local.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
android {
buildTypes {

def merchantAccount = System.getenv('ADYEN_ANDROID_MERCHANT_ACCOUNT')
def merchantServerUrl = System.getenv('ADYEN_ANDROID_MERCHANT_SERVER_URL')
def authorizationHeaderName = System.getenv('ADYEN_ANDROID_AUTHORIZATION_HEADER_NAME')
def authorizationHeaderValue = System.getenv('ADYEN_ANDROID_AUTHORIZATION_HEADER_VALUE')
def clientKey = System.getenv('ADYEN_ANDROID_CLIENT_KEY')

debug {
buildConfigField "String", "MERCHANT_ACCOUNT", "\"$merchantAccount\""
buildConfigField "String", "MERCHANT_SERVER_URL", "\"$merchantServerUrl\""
buildConfigField "String", "AUTHORIZATION_HEADER_NAME", "\"$authorizationHeaderName\""
buildConfigField "String", "AUTHORIZATION_HEADER_VALUE", "\"$authorizationHeaderValue\""
buildConfigField "String", "CLIENT_KEY", "\"$clientKey\""
buildConfigField "String", "MERCHANT_RECURRING_SERVER_URL", "\"$merchantServerUrl\""
}

release {
initWith debug
matchingFallbacks = ['debug']
}
}
}
7 changes: 0 additions & 7 deletions example-app/src/androidTest/AndroidManifest.xml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright (c) 2024 Adyen N.V.
*
* This file is open source and available under the MIT license. See the LICENSE file for more info.
*
* Created by oscars on 19/4/2024.
*/

package com.adyen.checkout

import android.app.Application
import android.content.Context
import androidx.test.runner.AndroidJUnitRunner
import dagger.hilt.android.testing.HiltTestApplication

// This class is used from build.gradle
@Suppress("Unused")
class HiltTestRunner : AndroidJUnitRunner() {

override fun newApplication(cl: ClassLoader?, name: String?, context: Context?): Application {
return super.newApplication(cl, HiltTestApplication::class.java.name, context)
}
}
Loading

0 comments on commit b937ea4

Please sign in to comment.