From d495207ac108e222fd24fec9b7e8a35478b26da5 Mon Sep 17 00:00:00 2001 From: Hannes Achleitner Date: Sun, 24 Sep 2023 20:27:23 +0200 Subject: [PATCH] Introduce Espresso tests It's a pre task for Strict violations oberservations --- .github/workflows/pull-request-ci.yml | 64 +++++++++++++++++-- exampleapp/build.gradle | 7 ++ .../java/org/matomo/demo/SmokeTest.kt | 43 +++++++++++++ 3 files changed, 109 insertions(+), 5 deletions(-) create mode 100644 exampleapp/src/androidTest/java/org/matomo/demo/SmokeTest.kt diff --git a/.github/workflows/pull-request-ci.yml b/.github/workflows/pull-request-ci.yml index 0ac0975d..1caa926b 100644 --- a/.github/workflows/pull-request-ci.yml +++ b/.github/workflows/pull-request-ci.yml @@ -7,8 +7,24 @@ on: pull_request: branches: - master +env: + BRANCH_NAME: ${{ github.head_ref || github.ref_name }} jobs: + env-job: + runs-on: ubuntu-latest + outputs: + modified-branch-name: ${{ steps.env.outputs.MODIFIED_BRANCH_NAME }} + name: Modify branch name + steps: + - name: Sets MODIFIED_BRANCH_NAME + id: env + env: + name: "${{env.BRANCH_NAME}}" + run: | + echo "MODIFIED_BRANCH_NAME=${name//\//-}" >> ${GITHUB_OUTPUT} + cat ${GITHUB_OUTPUT} + buildTest: name: Build & Run Unit-Tests runs-on: ubuntu-latest @@ -27,13 +43,15 @@ jobs: run: ./gradlew assembleDebug - name: Run tests run: ./gradlew test -# - name: Jacoco -# run: ./gradlew :tracker:jacocoTestReport -# - name: Codecov -# run: bash <(curl -s https://codecov.io/bash) + # - name: Jacoco + # run: ./gradlew :tracker:jacocoTestReport + # - name: Codecov + # run: bash <(curl -s https://codecov.io/bash) Check: name: Check runs-on: ubuntu-latest + needs: + - env-job steps: - name: Checkout uses: actions/checkout@v4 @@ -50,5 +68,41 @@ jobs: uses: actions/upload-artifact@v3.1.3 if: ${{ always() }} with: - name: Matomo-Lint-report + name: Matomo-Lint-${{ needs.env-job.outputs.modified-branch-name }} path: tracker/build/reports/lint-results.html + + EspressoTest: + runs-on: macOS-latest + needs: + - env-job + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + submodules: true + - name: show envs + run: | + echo ${{ needs.env-job.outputs.modified-branch-name }} + - name: prepare + run: brew install exiftool imagemagick + - name: set up JDK 17 + uses: actions/setup-java@v3 + with: + distribution: 'adopt' + java-version: 17 + - name: Install Android SDK + uses: malinskiy/action-android/install-sdk@release/0.1.4 + - name: Run instrumentation tests + uses: malinskiy/action-android/emulator-run-cmd@release/0.1.4 + with: + cmd: ./gradlew cAT --continue + api: 28 + tag: default + abi: x86_64 + cmdOptions: -noaudio -no-boot-anim -no-window + - name: Archive Espresso results + uses: actions/upload-artifact@v3 + if: ${{ always() }} + with: + name: matomo-Espresso-report + path: demo/build/reports/androidTests/connected diff --git a/exampleapp/build.gradle b/exampleapp/build.gradle index ebe1177b..3df3c665 100644 --- a/exampleapp/build.gradle +++ b/exampleapp/build.gradle @@ -9,6 +9,9 @@ android { targetSdkVersion project.ext.globalTargetSdkVersion versionCode 2 versionName "2.0" + + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + testInstrumentationRunnerArguments useTestStorageService: 'true' } buildTypes { release { @@ -30,4 +33,8 @@ dependencies { implementation 'androidx.legacy:legacy-support-v4:1.0.0' implementation "com.jakewharton.timber:timber:${timberVersion}" implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8" + + 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" } diff --git a/exampleapp/src/androidTest/java/org/matomo/demo/SmokeTest.kt b/exampleapp/src/androidTest/java/org/matomo/demo/SmokeTest.kt new file mode 100644 index 00000000..a0d9b9ea --- /dev/null +++ b/exampleapp/src/androidTest/java/org/matomo/demo/SmokeTest.kt @@ -0,0 +1,43 @@ +package org.matomo.demo + +import androidx.test.espresso.assertion.ViewAssertions.matches +import androidx.test.core.graphics.writeToTestStorage +import androidx.test.espresso.Espresso.onView +import androidx.test.espresso.action.ViewActions +import androidx.test.espresso.action.ViewActions.click +import androidx.test.espresso.matcher.ViewMatchers +import androidx.test.espresso.matcher.ViewMatchers.withId +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 +import org.matomo.demo.DemoActivity + +@RunWith(AndroidJUnit4::class) +class SmokeTest { + + private val WAIT_SLIDER = 600L + + @get:Rule + val activityScenarioRule = activityScenarioRule() + + @get:Rule + var nameRule = TestName() + + @Test + fun testExpand() { + onView(withId(R.id.trackMainScreenViewButton)).perform(click()) + onView(withId(R.id.trackDispatchNow)).perform(click()) + onView(withId(R.id.trackCustomVarsButton)).perform(click()) + onView(withId(R.id.raiseExceptionButton)).perform(click()) + onView(withId(R.id.addEcommerceItemButton)).perform(click()) + onView(withId(R.id.trackEcommerceCartUpdateButton)).perform(click()) + onView(withId(R.id.completeEcommerceOrderButton)).perform(click()) + onView(withId(R.id.trackGoalButton)).perform(click()) + onView(withId(R.id.goalTextEditView)).perform(click()) + } + +}