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

Introduce Espresso tests #437

Merged
merged 1 commit into from
Sep 24, 2023
Merged
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
64 changes: 59 additions & 5 deletions .github/workflows/pull-request-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
7 changes: 7 additions & 0 deletions exampleapp/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ android {
targetSdkVersion project.ext.globalTargetSdkVersion
versionCode 2
versionName "2.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
testInstrumentationRunnerArguments useTestStorageService: 'true'
}
buildTypes {
release {
Expand All @@ -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"
}
43 changes: 43 additions & 0 deletions exampleapp/src/androidTest/java/org/matomo/demo/SmokeTest.kt
Original file line number Diff line number Diff line change
@@ -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<DemoActivity>()

@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())
}

}
Loading