Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 19f996d7 authored by vadimt's avatar vadimt
Browse files

Exiting tests after a test fails to deinitialize

This avoid confusion when following tests get affected by failures in
earlier tests.

Change-Id: I44abcb38d5de222e48b0c33f062044280305750e
parent 1f95993e
Loading
Loading
Loading
Loading
+21 −6
Original line number Original line Diff line number Diff line
@@ -20,6 +20,8 @@ import static androidx.test.InstrumentationRegistry.getInstrumentation;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.Assert.fail;


import static java.lang.System.exit;

import android.app.Instrumentation;
import android.app.Instrumentation;
import android.content.BroadcastReceiver;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Context;
@@ -29,6 +31,7 @@ import android.content.pm.LauncherActivityInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager;
import android.os.Process;
import android.os.Process;
import android.os.RemoteException;
import android.os.RemoteException;
import android.util.Log;
import android.view.Surface;
import android.view.Surface;


import androidx.test.InstrumentationRegistry;
import androidx.test.InstrumentationRegistry;
@@ -81,6 +84,7 @@ public abstract class AbstractLauncherUiTest {
    public static final long SHORT_UI_TIMEOUT = 300;
    public static final long SHORT_UI_TIMEOUT = 300;
    public static final long DEFAULT_UI_TIMEOUT = 10000;
    public static final long DEFAULT_UI_TIMEOUT = 10000;
    protected static final int LONG_WAIT_TIME_MS = 60000;
    protected static final int LONG_WAIT_TIME_MS = 60000;
    private static final String TAG = "AbstractLauncherUiTest";


    protected MainThreadExecutor mMainThreadExecutor = new MainThreadExecutor();
    protected MainThreadExecutor mMainThreadExecutor = new MainThreadExecutor();
    protected final UiDevice mDevice;
    protected final UiDevice mDevice;
@@ -107,10 +111,12 @@ public abstract class AbstractLauncherUiTest {
    @Rule
    @Rule
    public LauncherActivityRule mActivityMonitor = new LauncherActivityRule();
    public LauncherActivityRule mActivityMonitor = new LauncherActivityRule();


    @Rule public ShellCommandRule mDefaultLauncherRule =
    @Rule
    public ShellCommandRule mDefaultLauncherRule =
            TestHelpers.isInLauncherProcess() ? ShellCommandRule.setDefaultLauncher() : null;
            TestHelpers.isInLauncherProcess() ? ShellCommandRule.setDefaultLauncher() : null;


    @Rule public ShellCommandRule mDisableHeadsUpNotification =
    @Rule
    public ShellCommandRule mDisableHeadsUpNotification =
            ShellCommandRule.disableHeadsUpNotification();
            ShellCommandRule.disableHeadsUpNotification();


    // Annotation for tests that need to be run in portrait and landscape modes.
    // Annotation for tests that need to be run in portrait and landscape modes.
@@ -164,9 +170,17 @@ public abstract class AbstractLauncherUiTest {
    }
    }


    @After
    @After
    public void tearDown() throws Exception {
    public void tearDown() {
        try {
            // Limits UI tests affecting tests running after them.
            // Limits UI tests affecting tests running after them.
            waitForModelLoaded();
            waitForModelLoaded();
        } catch (Throwable t) {
            Log.e(TAG,
                    "Couldn't deinit after a test, exiting tests, see logs for failures that "
                            + "could have caused this",
                    t);
            exit(1);
        }
    }
    }


    protected void lockRotation(boolean naturalOrientation) throws RemoteException {
    protected void lockRotation(boolean naturalOrientation) throws RemoteException {
@@ -189,6 +203,7 @@ public abstract class AbstractLauncherUiTest {


    /**
    /**
     * Scrolls the {@param container} until it finds an object matching {@param condition}.
     * Scrolls the {@param container} until it finds an object matching {@param condition}.
     *
     * @return the matching object.
     * @return the matching object.
     */
     */
    protected UiObject2 scrollAndFind(UiObject2 container, BySelector condition) {
    protected UiObject2 scrollAndFind(UiObject2 container, BySelector condition) {
+1 −1
Original line number Original line Diff line number Diff line
@@ -95,7 +95,7 @@ public class BindWidgetTest extends AbstractLauncherUiTest {
    }
    }


    @After
    @After
    public void tearDown() throws Exception {
    public void tearDown() {
        if (mCursor != null) {
        if (mCursor != null) {
            mCursor.close();
            mCursor.close();
        }
        }