Skip to content

Commit

Permalink
Espresso tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hannesa2 committed Jul 6, 2024
1 parent 20c217b commit 85f7334
Show file tree
Hide file tree
Showing 3 changed files with 127 additions and 5 deletions.
56 changes: 51 additions & 5 deletions .github/workflows/Android-CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,32 @@ name: CI Android
on: [pull_request]

jobs:
build:

runs-on: ubuntu-latest

Test:
runs-on: ${{ matrix.os }}
permissions:
contents: write
pull-requests: write
repository-projects: write
strategy:
fail-fast: false
matrix:
os: [ ubuntu-latest ]
api: [ 28 ]
tag: [ default ]
abi: [ x86_64 ]
emulatorApi: [ 9 ]
java_version: [ 17 ]
steps:
- name: kvm support
run: |
egrep -c '(vmx|svm)' /proc/cpuinfo
id
sudo adduser $USER kvm
sudo chown -R $USER /dev/kvm
id
- name: prepare
run: |
sudo apt-get update && sudo apt-get install -y exiftool imagemagick xdg-utils libimage-exiftool-perl zsh jq xorg
- uses: actions/checkout@v4
- name: set up JDK
uses: actions/setup-java@v4
Expand All @@ -16,4 +37,29 @@ jobs:
java-version: 17
- uses: gradle/wrapper-validation-action@v3
- name: Build with Gradle
run: ./gradlew build
run: ./gradlew assemble
- name: Install Android SDK
uses: hannesa2/action-android/[email protected]
- name: Run instrumentation tests
uses: hannesa2/action-android/[email protected]
with:
cmd: ./gradlew cAT --continue
api: ${{ matrix.api }}
tag: ${{ matrix.tag }}
abi: ${{ matrix.abi }}
cmdOptions: -noaudio -no-boot-anim -no-window -metrics-collection
- name: Archive screenshots
if: ${{ always() }}
uses: actions/[email protected]
with:
name: Updater-Screenshots
if-no-files-found: error
path: |
app/build/outputs/connected_android_test_additional_output/debugAndroidTest/connected
app/build/outputs/androidTest-results/connected
- name: Archive Espresso results
uses: actions/upload-artifact@v3
with:
if-no-files-found: error
name: Updater-Espresso-report
path: app/build/reports/androidTests/connected
7 changes: 7 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ android {
targetSdkVersion 34

buildConfigField "String", 'GIT_REPOSITORY', "\"" + getGitOriginRemote() + "\""

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
testInstrumentationRunnerArguments useTestStorageService: 'true'
}
packagingOptions {
resources {
Expand All @@ -39,6 +42,10 @@ dependencies {
implementation "androidx.appcompat:appcompat:1.7.0"
implementation 'com.google.android.material:material:1.12.0'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"

androidTestImplementation "androidx.test.ext:junit-ktx:1.1.4"
androidTestUtil "androidx.test.services:test-services:1.4.2"
androidTestImplementation "androidx.test.espresso:espresso-core:3.5.0"
}

static def getGitCommitCount() {
Expand Down
69 changes: 69 additions & 0 deletions app/src/androidTest/java/info/hannes/github/sample/SmokeTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package info.hannes.github.sample

import android.util.Log
import androidx.test.core.app.takeScreenshot
import androidx.test.core.graphics.writeToTestStorage
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.action.ViewActions.click
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.RootMatchers.isDialog
import androidx.test.espresso.matcher.ViewMatchers.*
import androidx.test.espresso.screenshot.captureToBitmap
import androidx.test.ext.junit.rules.activityScenarioRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import org.junit.Rule
import org.junit.Test
import org.junit.rules.TestName
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
class SmokeTest {

@get:Rule
val activityScenarioRule = activityScenarioRule<MainActivity>()

@get:Rule
var nameRule = TestName()

@Test
fun smokeTestSimplyStart() {
onView(isRoot())
.captureToBitmap()
.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}-R")

onView(withId(R.id.button)).perform(click())
onView(isRoot())
.captureToBitmap()
.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}-2")
onView(withText(info.hannes.github.R.string.new_version))
.inRoot(isDialog())
.check(matches(isDisplayed()))
onView(isRoot())
.captureToBitmap()
.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}-3")
}

@Test
fun updateGithub() {
onView(isRoot())
.captureToBitmap()
.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}-1")
onView(withId(R.id.button)).perform(click())
onView(isRoot())
.captureToBitmap()
.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}-2")
onView(withText(info.hannes.github.R.string.new_version))
.inRoot(isDialog())
.check(matches(isDisplayed()))
onView(isRoot())
.captureToBitmap()
.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}-3")

// close dialog
onView(withId(android.R.id.button1)).perform(click())

onView(isRoot())
.captureToBitmap()
.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}-4")
}
}

0 comments on commit 85f7334

Please sign in to comment.