diff --git a/app/src/test/java/com/droiddeck/launcher/ProtonMenuAutoTest.kt b/app/src/test/java/com/droiddeck/launcher/ProtonMenuAutoTest.kt index 4ea0a52d7f..dacf38c34c 100644 --- a/app/src/test/java/com/droiddeck/launcher/ProtonMenuAutoTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/ProtonMenuAutoTest.kt @@ -65,6 +65,7 @@ class ProtonMenuAutoTest { menu.protonProblem = null menu.protonStage = null menu.protonPercent = -1 + menu.experimentalRefresh = { emptyList() } menu.installer = { tool, progress -> progress("Installing ${tool.name}", 50) install("${tool.prefix}-11-12") diff --git a/app/src/test/java/com/droiddeck/launcher/session/TestJvmUncaughtHandler.kt b/app/src/test/java/com/droiddeck/launcher/session/TestJvmUncaughtHandler.kt new file mode 100644 index 0000000000..c95873aa2d --- /dev/null +++ b/app/src/test/java/com/droiddeck/launcher/session/TestJvmUncaughtHandler.kt @@ -0,0 +1,16 @@ +package com.droiddeck.launcher.session + +import org.robolectric.pluginapi.TestEnvironmentLifecyclePlugin + +/** + * A plain JVM has no default uncaught-exception handler, so CrashHandler's fallback halts the test JVM (exit 2) + * on any background-thread error. Each test starts from a handler that only prints, like the JVM's own. + */ +class TestJvmUncaughtHandler : TestEnvironmentLifecyclePlugin { + override fun onSetupApplicationState() { + Thread.setDefaultUncaughtExceptionHandler { thread, error -> + System.err.print("Exception in thread \"${thread.name}\" ") + error.printStackTrace(System.err) + } + } +} diff --git a/app/src/test/java/com/droiddeck/launcher/session/UncaughtBackgroundErrorTest.kt b/app/src/test/java/com/droiddeck/launcher/session/UncaughtBackgroundErrorTest.kt new file mode 100644 index 0000000000..d1409cce25 --- /dev/null +++ b/app/src/test/java/com/droiddeck/launcher/session/UncaughtBackgroundErrorTest.kt @@ -0,0 +1,21 @@ +package com.droiddeck.launcher.session + +import com.droiddeck.launcher.App +import org.junit.Assert.assertTrue +import org.junit.Test +import org.junit.runner.RunWith +import org.robolectric.RobolectricTestRunner +import org.robolectric.RuntimeEnvironment +import org.robolectric.annotation.Config + +@RunWith(RobolectricTestRunner::class) +@Config(sdk = [34]) +class UncaughtBackgroundErrorTest { + @Test fun anUncaughtErrorOnABackgroundThreadDoesNotEndTheTestRun() { + assertTrue(RuntimeEnvironment.getApplication() is App) + Thread({ throw IllegalStateException("expected by the test") }, "uncaught-background-error").apply { + start() + join() + } + } +} diff --git a/app/src/test/resources/META-INF/services/org.robolectric.pluginapi.TestEnvironmentLifecyclePlugin b/app/src/test/resources/META-INF/services/org.robolectric.pluginapi.TestEnvironmentLifecyclePlugin new file mode 100644 index 0000000000..d6d0a4d676 --- /dev/null +++ b/app/src/test/resources/META-INF/services/org.robolectric.pluginapi.TestEnvironmentLifecyclePlugin @@ -0,0 +1 @@ +com.droiddeck.launcher.session.TestJvmUncaughtHandler