ci: Instrumentation tests coverage in ci.
Some checks failed
Check PR code / EspressoReports (pull_request) Failing after 53m12s
Some checks failed
Check PR code / EspressoReports (pull_request) Failing after 53m12s
This commit is contained in:
@@ -96,6 +96,7 @@ android {
|
||||
// tests
|
||||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||
testInstrumentationRunnerArguments["clearPackageData"] = "true"
|
||||
testInstrumentationRunnerArguments["useTestStorageService"] = "true"
|
||||
}
|
||||
packaging {
|
||||
resources {
|
||||
@@ -109,6 +110,8 @@ android {
|
||||
proguardFiles(getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro")
|
||||
}
|
||||
getByName("debug") {
|
||||
isTestCoverageEnabled = true
|
||||
enableAndroidTestCoverage = true
|
||||
}
|
||||
}
|
||||
flavorDimensions.add("build")
|
||||
@@ -197,14 +200,16 @@ dependencies {
|
||||
testImplementation("io.mockk:mockk:1.13.14")
|
||||
testImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.10.1")
|
||||
implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.6.1")
|
||||
androidTestImplementation("androidx.test:runner:1.6.2")
|
||||
androidTestImplementation("androidx.test:rules:1.6.1")
|
||||
androidTestImplementation("androidx.test:runner:1.7.0-alpha01")
|
||||
androidTestImplementation("androidx.test:rules:1.7.0-alpha01")
|
||||
androidTestImplementation("androidx.test.espresso:espresso-core:3.6.1")
|
||||
implementation("androidx.test.espresso:espresso-idling-resource:3.6.1")
|
||||
androidTestImplementation("androidx.test.ext:junit-ktx:1.2.1")
|
||||
androidTestUtil("androidx.test:orchestrator:1.5.1")
|
||||
androidTestUtil("androidx.test:orchestrator:1.6.0-alpha02")
|
||||
androidTestUtil("androidx.test.services:test-services:1.6.0-alpha02")
|
||||
testImplementation("org.robolectric:robolectric:4.14.1")
|
||||
testImplementation("androidx.test:core-ktx:1.6.1")
|
||||
testImplementation("androidx.test:core-ktx:1.7.0-alpha01")
|
||||
androidTestImplementation("androidx.test.uiautomator:uiautomator:2.3.0")
|
||||
|
||||
implementation("ch.acra:acra-http:$acraVersion")
|
||||
implementation("ch.acra:acra-toast:$acraVersion")
|
||||
|
||||
@@ -2,6 +2,7 @@ package bou.amine.apps.readerforselfossv2.android
|
||||
|
||||
import android.content.Context
|
||||
import androidx.annotation.ArrayRes
|
||||
import androidx.test.espresso.Espresso
|
||||
import androidx.test.espresso.Espresso.onData
|
||||
import androidx.test.espresso.Espresso.onView
|
||||
import androidx.test.espresso.action.ViewActions.click
|
||||
@@ -9,13 +10,19 @@ import androidx.test.espresso.action.ViewActions.replaceText
|
||||
import androidx.test.espresso.action.ViewActions.typeTextIntoFocusedView
|
||||
import androidx.test.espresso.assertion.ViewAssertions.doesNotExist
|
||||
import androidx.test.espresso.assertion.ViewAssertions.matches
|
||||
import androidx.test.espresso.base.DefaultFailureHandler
|
||||
import androidx.test.espresso.matcher.ViewMatchers.isChecked
|
||||
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
|
||||
import androidx.test.espresso.matcher.ViewMatchers.isNotChecked
|
||||
import androidx.test.espresso.matcher.ViewMatchers.withId
|
||||
import androidx.test.espresso.matcher.ViewMatchers.withText
|
||||
import androidx.test.platform.app.InstrumentationRegistry.getInstrumentation
|
||||
import androidx.test.uiautomator.UiDevice
|
||||
import androidx.test.uiautomator.UiSelector
|
||||
import org.hamcrest.CoreMatchers.allOf
|
||||
import org.hamcrest.Matchers.hasToString
|
||||
import org.junit.Before
|
||||
import java.util.Locale
|
||||
|
||||
fun performLogin(someUrl: String? = null) {
|
||||
onView(withId(R.id.urlView)).perform(click()).perform(
|
||||
@@ -119,3 +126,38 @@ fun testAddSourceWithUrl(
|
||||
.perform(click())
|
||||
onView(withText(sourceName)).check(matches(isDisplayed()))
|
||||
}
|
||||
|
||||
open class WithANRException {
|
||||
// Running count of the number of Android Not Responding dialogues to prevent endless dismissal.
|
||||
private var anrCount = 0
|
||||
|
||||
// `RootViewWithoutFocusException` class is private, need to match the message (instead of using type matching).
|
||||
private val rootViewWithoutFocusExceptionMsg =
|
||||
java.lang.String.format(
|
||||
Locale.ROOT,
|
||||
"Waited for the root of the view hierarchy to have " +
|
||||
"window focus and not request layout for 10 seconds. If you specified a non " +
|
||||
"default root matcher, it may be picking a root that never takes focus. " +
|
||||
"Root:",
|
||||
)
|
||||
|
||||
@Before
|
||||
fun setUpHandler() {
|
||||
Espresso.setFailureHandler { error, viewMatcher ->
|
||||
|
||||
if (error.message!!.contains(rootViewWithoutFocusExceptionMsg) && anrCount < 3) {
|
||||
anrCount++
|
||||
handleAnrDialogue()
|
||||
} else { // chain all failures down to the default espresso handler
|
||||
DefaultFailureHandler(getInstrumentation().targetContext).handle(error, viewMatcher)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun handleAnrDialogue() {
|
||||
val device = UiDevice.getInstance(getInstrumentation())
|
||||
// If running the device in English Locale
|
||||
val waitButton = device.findObject(UiSelector().textContains("wait"))
|
||||
if (waitButton.exists()) waitButton.click()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ import org.junit.runner.RunWith
|
||||
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
@LargeTest
|
||||
class HomeActivityTest {
|
||||
class HomeActivityTest : WithANRException() {
|
||||
@get:Rule
|
||||
val activityRule = ActivityScenarioRule(LoginActivity::class.java)
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ import org.junit.runner.RunWith
|
||||
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
@LargeTest
|
||||
class LoginActivityTest {
|
||||
class LoginActivityTest : WithANRException() {
|
||||
@get:Rule
|
||||
val activityRule = ActivityScenarioRule(LoginActivity::class.java)
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ import org.junit.runner.RunWith
|
||||
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
@LargeTest
|
||||
class SettingsActivityGeneralTest {
|
||||
class SettingsActivityGeneralTest : WithANRException() {
|
||||
@get:Rule
|
||||
val activityRule = ActivityScenarioRule(LoginActivity::class.java)
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ import org.junit.runner.RunWith
|
||||
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
@LargeTest
|
||||
class SettingsActivityOfflineTest {
|
||||
class SettingsActivityOfflineTest : WithANRException() {
|
||||
@get:Rule
|
||||
val activityRule = ActivityScenarioRule(LoginActivity::class.java)
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ import org.junit.runner.RunWith
|
||||
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
@LargeTest
|
||||
class SettingsActivityReaderTest {
|
||||
class SettingsActivityReaderTest : WithANRException() {
|
||||
@get:Rule
|
||||
val activityRule = ActivityScenarioRule(LoginActivity::class.java)
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ import org.junit.runner.RunWith
|
||||
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
@LargeTest
|
||||
class SettingsActivityTest {
|
||||
class SettingsActivityTest : WithANRException() {
|
||||
@get:Rule
|
||||
val activityRule = ActivityScenarioRule(LoginActivity::class.java)
|
||||
lateinit var context: Context
|
||||
|
||||
@@ -23,7 +23,7 @@ import java.util.UUID
|
||||
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
@LargeTest
|
||||
class SourcesActivityTest {
|
||||
class SourcesActivityTest : WithANRException() {
|
||||
@get:Rule
|
||||
val activityRule = ActivityScenarioRule(LoginActivity::class.java)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user