Skip to content

Commit d27810e

Browse files
Refactor CI configuration for Android tests
1 parent 0f0b4b3 commit d27810e

File tree

5 files changed

+38
-45
lines changed

5 files changed

+38
-45
lines changed

.github/workflows/android_test_ci.yml

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,29 @@ jobs:
44
instrumentation_tests:
55
runs-on: ubuntu-latest
66
steps:
7-
- name: checkout repository
8-
uses: actions/checkout@v4
9-
- name: set up JDK 21
10-
uses: actions/setup-java@v4
11-
with:
12-
distribution: 'zulu'
13-
java-version: '21'
14-
- name: set up Android SDK
15-
uses: android-actions/setup-android@v3
16-
- name: build APKs
17-
run: |
18-
./gradlew assembleDebug
19-
./gradlew assembleAndroidTest
20-
- name: run tests
21-
uses: emulator-wtf/run-tests@v0
22-
with:
23-
api-token: ${{ secrets.EW_API_TOKEN }}
24-
app: app/build/outputs/apk/debug/app-debug.apk
25-
test: app/build/outputs/apk/androidTest/app-debug-androidTest.apk
26-
outputs-dir: build/test-results
27-
- name: publish test results
28-
uses: mikepenz/action-junit-report@v5
29-
if: always()
30-
with:
31-
report_paths: 'build/test-results/**/*.xml'
32-
7+
- name: checkout repository
8+
uses: actions/checkout@v4
9+
- name: set up JDK 21
10+
uses: actions/setup-java@v4
11+
with:
12+
distribution: 'zulu'
13+
java-version: '21'
14+
- name: set up Android SDK
15+
uses: android-actions/setup-android@v3
16+
- name: build app apk
17+
run: bash ./gradlew assembleDebug
18+
- name: build android test apk
19+
run: bash ./gradlew assembleAndroidTest
20+
- name: run tests
21+
uses: emulator-wtf/run-tests@v0
22+
with:
23+
api-token: ${{ secrets.EW_API_TOKEN }}
24+
app: app/build/outputs/apk/debug/app-debug.apk
25+
test: app/build/outputs/apk/androidTest/debug/app-debug-androidTest.apk
26+
outputs-dir: build/test-results
27+
- name: publish test results
28+
uses: mikepenz/action-junit-report@v5
29+
if: always()
30+
with:
31+
report_paths: 'build/test-results/**/*.xml'
32+

app/src/androidTest/kotlin/com/vrem/wifianalyzer/FilterInstrumentedTest.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ package com.vrem.wifianalyzer
2020
import androidx.test.espresso.Espresso.onView
2121
import androidx.test.espresso.action.ViewActions.click
2222
import androidx.test.espresso.action.ViewActions.scrollTo
23+
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
2324
import androidx.test.espresso.matcher.ViewMatchers.withId
25+
import org.hamcrest.Matchers.allOf
2426

2527
internal class FilterInstrumentedTest : Runnable {
2628
override fun run() {
27-
onView(withId(R.id.action_filter)).perform(click())
28-
pauseShort()
29-
onView(withId(android.R.id.button3)).perform(scrollTo(), click())
30-
pauseShort()
29+
onView(allOf(withId(R.id.action_filter), isDisplayed())).perform(click())
30+
onView(allOf(withId(android.R.id.button3), isDisplayed())).perform(scrollTo(), click())
3131
}
3232
}

app/src/androidTest/kotlin/com/vrem/wifianalyzer/InstrumentedTestUtils.kt

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,16 @@ package com.vrem.wifianalyzer
2020
import android.view.View
2121
import android.view.ViewGroup
2222
import androidx.appcompat.widget.Toolbar
23-
import androidx.test.espresso.Espresso
23+
import androidx.test.espresso.Espresso.pressBack
2424
import androidx.test.espresso.matcher.BoundedMatcher
2525
import org.hamcrest.Description
2626
import org.hamcrest.Matcher
2727
import org.hamcrest.TypeSafeMatcher
2828

29-
internal class ChildAtPosition(private val parentMatcher: Matcher<View>, private val position: Int) : TypeSafeMatcher<View>() {
29+
private const val SLEEP_1_SECOND = 1000
30+
private const val SLEEP_3_SECONDS = 3000
31+
32+
internal class ChildAtPosition(val parentMatcher: Matcher<View>, val position: Int) : TypeSafeMatcher<View>() {
3033
override fun describeTo(description: Description) {
3134
description.appendText("Child at position $position in parent ")
3235
parentMatcher.describeTo(description)
@@ -49,20 +52,16 @@ internal fun withToolbarTitle(expectedTitle: CharSequence): Matcher<View> {
4952
}
5053
}
5154

52-
private const val SLEEP_TIME_SHORT = 5000
53-
private const val SLEEP_TIME_LONG = SLEEP_TIME_SHORT * 3
54-
5555
internal fun pressBackButton() {
56-
pauseShort()
57-
Espresso.pressBack()
56+
pressBack()
5857
}
5958

6059
internal fun pauseShort() {
61-
pause(SLEEP_TIME_SHORT)
60+
pause(SLEEP_1_SECOND)
6261
}
6362

6463
internal fun pauseLong() {
65-
pause(SLEEP_TIME_LONG)
64+
pause(SLEEP_3_SECONDS)
6665
}
6766

6867
private fun pause(sleepTime: Int) {

app/src/androidTest/kotlin/com/vrem/wifianalyzer/NavigationInstrumentedTest.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,12 @@ internal class NavigationInstrumentedTest : Runnable {
4141
8 to "Vendors"
4242
).forEach { (id, title) ->
4343
selectMenuItem(id, title)
44-
pauseShort()
4544
}
4645
listOf(
4746
10 to "Settings",
4847
11 to "About"
4948
).forEach { (id, title) ->
5049
selectMenuItem(id, title)
51-
pauseShort()
5250
pressBackButton()
5351
}
5452
}

app/src/androidTest/kotlin/com/vrem/wifianalyzer/ScannerInstrumentedTest.kt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,7 @@ internal class ScannerInstrumentedTest : Runnable {
3030

3131
override fun run() {
3232
onView(allOf(withId(action_scanner), withContentDescription(PAUSE), isDisplayed())).perform(click())
33-
pauseShort()
3433
onView(allOf(withId(action_scanner), withContentDescription(PLAY), isDisplayed())).perform(click())
35-
pauseShort()
36-
onView(allOf(withId(action_scanner), withContentDescription(PAUSE), isDisplayed()))
37-
pauseShort()
3834
}
3935

4036
}

0 commit comments

Comments
 (0)