Add Test Butler and restore offline login test

This commit is contained in:
Matthieu 2021-05-08 21:58:14 +02:00
parent 0ebabf3fa7
commit 8a925c1e2f
3 changed files with 32 additions and 14 deletions

View File

@ -27,7 +27,7 @@ android {
versionCode 11
versionName "1.0.beta1"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
testInstrumentationRunner "org.pixeldroid.app.testUtility.TestRunner"
testInstrumentationRunnerArguments clearPackageData: 'true'
}
lintOptions{
@ -188,6 +188,9 @@ dependencies {
* Not in release, so not mentioned in licenses list
*/
androidTestImplementation 'com.linkedin.testbutler:test-butler-library:2.2.1'
androidTestUtil 'com.linkedin.testbutler:test-butler-app:2.2.1'
// debugImplementation required vs testImplementation: https://issuetracker.google.com/issues/128612536
//noinspection FragmentGradleConfiguration
stagingImplementation("androidx.fragment:fragment-testing:1.3.3") {

View File

@ -1,5 +1,5 @@
package org.pixeldroid.app
/*
import android.content.Context
import androidx.test.core.app.ActivityScenario
import androidx.test.core.app.ApplicationProvider
@ -12,6 +12,7 @@ import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry.getInstrumentation
import androidx.test.uiautomator.UiDevice
import androidx.test.uiautomator.UiSelector
import com.linkedin.android.testbutler.TestButler
import org.pixeldroid.app.testUtility.clearData
import org.pixeldroid.app.testUtility.initDB
import org.pixeldroid.app.utils.db.AppDatabase
@ -21,21 +22,13 @@ import org.junit.Rule
import org.junit.Test
import org.junit.rules.Timeout
import org.junit.runner.RunWith
import org.pixeldroid.app.testUtility.waitForView
@RunWith(AndroidJUnit4::class)
class LoginActivityOfflineTest {
private lateinit var context: Context
companion object {
fun switchAirplaneMode() {
val device = UiDevice.getInstance(getInstrumentation())
device.openQuickSettings()
device.findObject(UiSelector().textContains("Airplane")).click()
device.pressHome()
}
}
private lateinit var db: AppDatabase
@get:Rule
@ -43,7 +36,8 @@ class LoginActivityOfflineTest {
@Before
fun before() {
switchAirplaneMode()
TestButler.setWifiState(false)
TestButler.setGsmState(false)
context = ApplicationProvider.getApplicationContext<Context>()
db = initDB(context)
db.clearAllTables()
@ -52,19 +46,22 @@ class LoginActivityOfflineTest {
@Test
fun emptyDBandOfflineModeDisplayCorrectMessage() {
waitForView(R.id.login_activity_connection_required)
onView(withId(R.id.login_activity_connection_required)).check(matches(isDisplayed()))
}
@Test
fun retryButtonReloadsLoginActivity() {
waitForView(R.id.login_activity_connection_required_button)
onView(withId(R.id.login_activity_connection_required_button)).perform(click())
onView(withId(R.id.login_activity_connection_required)).check(matches(isDisplayed()))
}
@After
fun after() {
switchAirplaneMode()
TestButler.setWifiState(true)
TestButler.setGsmState(true)
db.close()
clearData()
}
}*/
}

View File

@ -0,0 +1,18 @@
package org.pixeldroid.app.testUtility
import android.os.Bundle
import androidx.test.runner.AndroidJUnitRunner
import com.linkedin.android.testbutler.TestButler
class TestRunner: AndroidJUnitRunner() {
override fun onStart() {
TestButler.setup(targetContext)
super.onStart()
}
override fun finish(resultCode: Int, results: Bundle) {
TestButler.teardown(targetContext)
super.finish(resultCode, results)
}
}