Verified Commit e9c36521 authored by Beatriz Rizental's avatar Beatriz Rizental Committed by Pier Angelo Vendrame
Browse files

TB 43243: [android] Implement Android launch test

Also remove exit call from terminate function.
It causes all espresso tests to crash on exit and otherwise doesn't do anything.
parent 9cf01e44
Loading
Loading
Loading
Loading
+40 −0
Original line number Diff line number Diff line
package org.mozilla.fenix

import androidx.test.ext.junit.rules.ActivityScenarioRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.uiautomator.UiDevice
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import java.util.concurrent.CountDownLatch
import java.util.concurrent.TimeUnit


@RunWith(AndroidJUnit4::class)
class LaunchTest {

    @get:Rule
    var rule: ActivityScenarioRule<HomeActivity> = ActivityScenarioRule(HomeActivity::class.java)

    @Test
    fun appLaunchesWithoutCrash() {
        val device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
        device.waitForIdle()

        // Simulate a 30-second delay
        val latch = CountDownLatch(1)
        Thread {
            try {
                Thread.sleep(30_000)
                latch.countDown()
            } catch (e: InterruptedException) {
                e.printStackTrace()
            }
        }.start()

        latch.await(30, TimeUnit.SECONDS)

        // If we got here, the app did not crash. Test passed.
    }
}
+0 −1
Original line number Diff line number Diff line
@@ -192,7 +192,6 @@ open class FenixApplication : LocaleAwareApplication(), Provider {

    fun terminate() {
        onTerminate()
        System.exit(0)
    }

    override fun onTerminate() {