diff --git a/.github/workflows/Android-CI.yml b/.github/workflows/Android-CI.yml index 5c32c8b..e3205e4 100644 --- a/.github/workflows/Android-CI.yml +++ b/.github/workflows/Android-CI.yml @@ -31,36 +31,32 @@ 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.2 - # with: - # cmd: ./gradlew cAT -Ponly_x86_64 --continue - # api: 28 - # tag: default - # abi: arm64-v8a - # - name: Archive Espresso results - # uses: actions/upload-artifact@v2.1.4 - # 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/upload-artifact@v2.1.4 - # if: ${{ always() }} - # with: - # name: MediaPipe-Screenshots - # path: applications/screenshots/adb/ + - 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: x86_64 + cmdOptions: -noaudio -no-boot-anim -no-window + - name: Archive Espresso results + uses: actions/upload-artifact@v2.1.4 + if: ${{ always() }} + with: + name: MediaPipe-Espresso-report + path: applications/**/build/reports/androidTests/connected/ + - name: Archive screenshots + if: ${{ always() }} + uses: actions/upload-artifact@v3 + with: 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: diff --git a/app/build.gradle b/app/build.gradle index 67a5277..aa09c8c 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -22,6 +22,7 @@ android { } testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + testInstrumentationRunnerArguments useTestStorageService: 'true' } signingConfigs { @@ -79,11 +80,10 @@ dependencies { implementation 'androidx.preference:preference-ktx:1.2.0' implementation 'com.github.hannesa2:githubAppUpdate:1.5' - androidTestImplementation 'com.github.AppDevNext:Moka:1.5' - androidTestImplementation "androidx.test.ext:junit:1.1.4" - androidTestImplementation 'androidx.test:runner:1.5.1' - androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.0' - androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.5.0' + 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" + androidTestImplementation "androidx.test:rules:1.5.0" // GrantPermissionRule } static def getGitOriginRemote() { diff --git a/app/src/androidTest/java/info/mediapipe/multihand/app/SmokeTest.kt b/app/src/androidTest/java/info/mediapipe/multihand/app/SmokeTest.kt index a068d8b..8f22042 100644 --- a/app/src/androidTest/java/info/mediapipe/multihand/app/SmokeTest.kt +++ b/app/src/androidTest/java/info/mediapipe/multihand/app/SmokeTest.kt @@ -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() + + // 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()) + } + } } } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index f701a9e..6f36397 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -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"