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

Espresso tests #28

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
49 changes: 23 additions & 26 deletions .github/workflows/Android-CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,36 +44,33 @@ jobs:
- name: Debug keystore
run: keytool -genkey -v -keystore app/debug.keystore -storepass android -alias androiddebugkey -keypass android -keyalg RSA -keysize 2048 -validity 10000 -dname "C=US, O=Android, CN=Android Debug"
- name: Build project
run: ./gradlew clean assembleDebug -Ponly_x86_64
run: ./gradlew assembleDebug -Ponly_x86_64
env:
VERSION: ${{steps.tagger.outputs.tag}}
- name: Run tests
run: ./gradlew test -Ponly_x86_64
# - name: Run instrumentation tests
# uses: malinskiy/action-android/emulator-run-cmd@release/0.1.4
# with:
# cmd: ./gradlew cAT -Ponly_x86_64 --continue
# api: 28
# tag: default
# abi: arm64-v8a
# - name: Archive Espresso results
# uses: actions/[email protected]
# if: ${{ always() }}
# with:
# name: MediaPipe-Espresso-report
# path: applications/**/build/reports/androidTests/connected/
# - name: Save logcat output
# uses: actions/upload-artifact@master
# if: failure()
# with:
# name: MediaPipe-logcat
# path: artifacts/logcat.log
# - name: Archive screenshots
# uses: actions/[email protected]
# if: ${{ always() }}
# with:
# name: MediaPipe-Screenshots
# path: applications/screenshots/adb/
- name: Run instrumentation tests
uses: hannesa2/action-android/[email protected]
with:
cmd: ./gradlew cAT -Ponly_x86_64 --continue
api: 28
tag: default
abi: x86_64
cmdOptions: -noaudio -no-boot-anim -no-window
- name: Archive Espresso results
uses: actions/[email protected]
if: ${{ always() }}
with:
name: MediaPipe-Espresso-report
path: applications/**/build/reports/androidTests/connected/
- name: Archive screenshots
if: ${{ always() }}
uses: actions/upload-artifact@v3
with:
name: Multihand-Screenshots
path: |
app/build/outputs/connected_android_test_additional_output/debugAndroidTest/connected
app/build/outputs/androidTest-results/connected
- name: cleanup keystore
run: ./signing/cleanup.sh
Check:
Expand Down
10 changes: 5 additions & 5 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ android {
jvmTarget = '17'
}
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
testInstrumentationRunnerArguments useTestStorageService: 'true'
}

signingConfigs {
Expand Down Expand Up @@ -83,11 +84,10 @@ dependencies {
implementation 'androidx.preference:preference-ktx:1.2.1'
implementation 'com.github.hannesa2:githubAppUpdate:2.3.1'

androidTestImplementation 'com.github.AppDevNext:Moka:1.6'
androidTestImplementation "androidx.test.ext:junit:1.2.0"
androidTestImplementation 'androidx.test:runner:1.6.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.6.0'
androidTestImplementation "androidx.test.ext:junit-ktx:1.1.5"
androidTestUtil "androidx.test.services:test-services:1.4.2"
androidTestImplementation "androidx.test.espresso:espresso-core:3.5.1"
androidTestImplementation "androidx.test:rules:1.5.0" // GrantPermissionRule
}

static def getGitOriginRemote() {
Expand Down
41 changes: 29 additions & 12 deletions app/src/androidTest/java/info/mediapipe/multihand/app/SmokeTest.kt
Original file line number Diff line number Diff line change
@@ -1,34 +1,51 @@
package info.mediapipe.multihand.app

import android.Manifest
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.ext.junit.rules.ActivityScenarioRule
import android.util.Log
import androidx.test.core.app.takeScreenshot
import androidx.test.core.graphics.writeToTestStorage
import androidx.test.espresso.Espresso
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 androidx.test.rule.GrantPermissionRule
import com.moka.utils.Screenshot
import info.mediapipe.app.R
import info.mediapipe.app.multihand.MultiHandActivity
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
var activityScenarioRule = ActivityScenarioRule(MultiHandActivity::class.java)
val activityScenarioRule = activityScenarioRule<MultiHandActivity>()

// a handy JUnit rule that stores the method name, so it can be used to generate unique screenshot files per test method
@get:Rule
var nameRule = TestName()

@get:Rule
val grantPermissionRule: GrantPermissionRule = GrantPermissionRule.grant(
Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.READ_EXTERNAL_STORAGE)
Manifest.permission.CAMERA,
Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.READ_EXTERNAL_STORAGE
)

@Test
fun smokeTestSimplyStart() {
onView(withId(R.id.preview_display_layout)).check(matches(isDisplayed()))
Screenshot.takeScreenshot("smoke")
for (i in 3000L..5000L step 1000) {
Thread.sleep(i)
takeScreenshot()
.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}-S$i")
try {
Espresso.onView(ViewMatchers.isRoot())
.captureToBitmap()
.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}-A$i")
} catch (e: Exception) {
Log.e("smokeTestSimplyStart", e.message.toString())
}
}
}
}
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
android:name=".HandApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:installLocation="auto"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme"
Expand Down
Loading