Skip to content

Commit

Permalink
Merge pull request #22 from arburk/feat/#9_InstrumentedTests
Browse files Browse the repository at this point in the history
Configured instrumented testing
  • Loading branch information
arburk authored Feb 5, 2024
2 parents ac1630a + b3b62ad commit 39de79a
Show file tree
Hide file tree
Showing 12 changed files with 362 additions and 147 deletions.
113 changes: 69 additions & 44 deletions .github/workflows/android_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,49 +4,74 @@ on: [push]

jobs:
build:

runs-on: ubuntu-latest
runs-on: ubuntu-latest # https://github.com/actions/runner-images/blob/main/images/ubuntu/Ubuntu2204-Readme.md
env:
JAVA_TOOL_OPTIONS: -Xmx4g

steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
cache: gradle

- name: Cache SonarCloud packages
uses: actions/cache@v3
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- name: Cache Gradle packages
uses: actions/cache@v3
with:
path: ~/.gradle/caches
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }}
restore-keys: ${{ runner.os }}-gradle

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

- name: Build with Gradle
run: ./gradlew clean build testDebugUnitTest jacocoTestReport

- name: Sonar checks
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: ./gradlew sonar

- name: Upload test results
uses: actions/upload-artifact@v3
with:
name: Reports
path: ${{ github.workspace }}/app/build/reports/
retention-days: 14
- name: checkout source
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
cache: gradle

- name: Cache SonarCloud packages
uses: actions/cache@v4
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar

- name: Cache Gradle packages
uses: actions/cache@v4
with:
path: ~/.gradle/caches
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }}
restore-keys: ${{ runner.os }}-gradle

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

- name: Build with Gradle
run: ./gradlew clean build

- name: Enable KVM group perms
# https://github.blog/changelog/2023-02-23-hardware-accelerated-android-virtualization-on-actions-windows-and-linux-larger-hosted-runners/
# Starting on February 23, 2023, Actions users of GitHub-hosted larger Linux runners will be able to make use of hardware acceleration for Android testing
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: Perform instrumented API Level 33 Test
uses: reactivecircus/android-emulator-runner@v2
id: perform-it
continue-on-error: true
with: # run ``sdkmanager --list`` to see available images
api-level: 33
target: aosp_atd
arch: x86_64
channel: canary
emulator-boot-timeout: 300
emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none -logcat-output ${{ github.workspace }}/app/build/reports/avd33.log
disable-animations: true
script: ./gradlew connectedCheck

- name: Sonar checks
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: ./gradlew jacocoTestReport sonar

- name: Upload test results
uses: actions/upload-artifact@v4
with:
name: Reports
path: ${{ github.workspace }}/app/build/reports/
retention-days: 14
95 changes: 95 additions & 0 deletions .github/workflows/connected_check_on_pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
name: Instrumented Tests

on:
pull_request:
types: [opened, reopened, synchronize]

jobs:
build:
runs-on: ubuntu-latest # https://github.com/actions/runner-images/blob/main/images/ubuntu/Ubuntu2204-Readme.md
timeout-minutes: 60
strategy:
# Allow tests to continue on other devices if they fail on one device.
fail-fast: false
matrix:
api-level: [ 27, 28, 29, 30, 31, 32, 33, 34 ]
env:
JAVA_TOOL_OPTIONS: -Xmx4g

steps:
- name: checkout source
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
cache: gradle

- name: Cache Gradle packages
uses: actions/cache@v4
with:
path: ~/.gradle/caches
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }}
restore-keys: ${{ runner.os }}-gradle

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

- name: Build with Gradle
uses: gradle/gradle-build-action@v3

- name: Enable KVM group perms
# https://github.blog/changelog/2023-02-23-hardware-accelerated-android-virtualization-on-actions-windows-and-linux-larger-hosted-runners/
# Starting on February 23, 2023, Actions users of GitHub-hosted larger Linux runners will be able to make use of hardware acceleration for Android testing
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: Determine emulator target
id: determine-target
run: |
TARGET="google_apis"
if [[ ${{ matrix.api-level }} -ge 30 ]]; then
TARGET="aosp_atd"
elif [[ ${{ matrix.api-level }} -le 27 ]]; then
TARGET="default"
fi
echo "TARGET=$TARGET" >> "$GITHUB_OUTPUT"
# - name: AVD cache
# if: steps.check_pr.outputs.PERFORM_TEST != 0
# uses: actions/cache@v4
# id: avd-cache
# with:
# path: |
# ~/.android/avd/*
# ~/.android/adb*
# key: avd-ubuntu-${{ matrix.api-level }}

- name: Perfom instrumented tests
uses: reactivecircus/android-emulator-runner@v2
with:
api-level: ${{ matrix.api-level }}
target: ${{ steps.determine-target.outputs.TARGET }}
arch: x86_64
channel: canary
force-avd-creation: false
emulator-boot-timeout: 300
emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none -logcat-output ${{ github.workspace }}/app/build/reports/avd${{ matrix.api-level }}.log
disable-animations: true
script: ./gradlew connectedCheck

- name: Upload test results
uses: actions/upload-artifact@v4
if: always()
with:
name: test-results-${{ matrix.api-level }}-${{ steps.determine-target.outputs.TARGET }}
path: |
**/build/reports/*
**/build/outputs/*/connected/*
retention-days: 14
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@
.externalNativeBuild
.cxx
local.properties
/Github.http
51 changes: 35 additions & 16 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ plugins {
id 'org.jetbrains.kotlin.android'
id 'jacoco'
id "org.sonarqube" version "4.2.1.3168"
id("de.mannodermaus.android-junit5") version "1.10.0.0"
}

android {
Expand All @@ -16,8 +17,10 @@ android {
versionCode 1
versionName "1.0"

//testInstrumentationRunner "com.github.arburk.vscp.app.AndroidJunitRunnerWithDexOpener"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
// Make sure to use the AndroidJUnitRunner (or a sub-class) in order to hook in the JUnit 5 Test Builder
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
testInstrumentationRunnerArguments["runnerBuilder"] = "de.mannodermaus.junit5.AndroidJUnit5Builder"
testInstrumentationRunnerArguments["configurationParameters"] = "junit.jupiter.execution.parallel.enabled=true,junit.jupiter.execution.parallel.mode.default=concurrent"
}

buildTypes {
Expand Down Expand Up @@ -68,12 +71,31 @@ android {
apiLevel = 27
systemImageSource = "aosp"
}
nexus5api28(com.android.build.api.dsl.ManagedVirtualDevice) {
device = "Nexus 5"
apiLevel = 28
systemImageSource = "aosp"
}
pixel3api30(com.android.build.api.dsl.ManagedVirtualDevice) {
device = "Pixel 3"
apiLevel = 30
// Also use the AOSP Automated Test Device image for better emulator performance
systemImageSource = "aosp-atd"
}
pixel6api33(com.android.build.api.dsl.ManagedVirtualDevice) {
device = "Pixel 6"
apiLevel = 33
// Also use the AOSP Automated Test Device image for better emulator performance
systemImageSource = "aosp-atd"
}
}
groups {
supportedSdks {
//targetDevices.add(devices.nexus5api27)
targetDevices.add(devices.nexus5api28)
//targetDevices.add(devices.pixel3api30)
//targetDevices.add(devices.pixel6api33)
}
}
}

Expand Down Expand Up @@ -107,11 +129,6 @@ jacoco {

tasks.register('jacocoTestReport', JacocoReport) {
dependsOn(testDebugUnitTest)
dependsOn(testReleaseUnitTest)
//dependsOn(compileDebugJavaWithJavac)
//dependsOn(compileDebugKotlin)
//dependsOn(nexus5api27DebugAndroidTest)
//dependsOn(pixel3api30DebugAndroidTest)

reports {
xml.getRequired().set(true)
Expand All @@ -127,7 +144,7 @@ tasks.register('jacocoTestReport', JacocoReport) {
executionData.setFrom(fileTree(dir: "$projectDir/build", includes: [
"jacoco/testReleaseUnitTest.exec",
"outputs/unit_test_code_coverage/debugUnitTest/testDebugUnitTest.exec",
// "outputs/managed_device_code_coverage/**/coverage.ec",
"outputs/managed_device_code_coverage/**/coverage.ec",
// "outputs/code_coverage/debugAndroidTest/connected/**/coverage.ec",
]))
}
Expand All @@ -154,16 +171,18 @@ dependencies {
// Optional -- Robolectric environment
// testImplementation "androidx.test:core:$androidXTestVersion"

// Optional -- mockito-kotlin
// testImplementation "org.mockito.kotlin:mockito-kotlin:$mockitoKotlinVersion"
// Optional -- Mockk framework
// testImplementation "io.mockk:mockk:$mockkVersion"

testImplementation 'androidx.test.ext:junit-ktx:1.1.5'

androidTestImplementation 'com.github.tmurakami:dexopener:2.0.5'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
// androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
androidTestImplementation 'androidx.test:runner:1.5.2'
// Android Instrumentation Tests wth JUnit 5
androidTestImplementation "org.junit.jupiter:junit-jupiter-api:$junitJupiterVersion"
androidTestImplementation "org.junit.jupiter:junit-jupiter-params:$junitJupiterVersion"
androidTestImplementation "de.mannodermaus.junit5:android-test-core:1.4.0"
androidTestRuntimeOnly "de.mannodermaus.junit5:android-test-runner:1.4.0"
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'


//androidTestImplementation 'androidx.test:runner:1.5.2'
// androidTestImplementation 'androidx.test:rules:1.5.0'
// androidTestImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.7.1'
// androidTestImplementation "io.mockk:mockk-android:$mockkVersion"
Expand Down

This file was deleted.

Loading

0 comments on commit 39de79a

Please sign in to comment.