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

Commit f7205c76 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Not trying to disable running tests after a failed finalizer" into ub-launcher3-master

parents 421946a8 68e85785
Loading
Loading
Loading
Loading
+0 −33
Original line number Diff line number Diff line
@@ -8,7 +8,6 @@ import androidx.test.uiautomator.UiDevice;

import org.junit.rules.TestWatcher;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;

import java.io.ByteArrayOutputStream;
import java.io.File;
@@ -16,7 +15,6 @@ import java.io.IOException;

public class FailureWatcher extends TestWatcher {
    private static final String TAG = "FailureWatcher";
    private static boolean sHadFailedTestDeinitialization;
    final private UiDevice mDevice;

    public FailureWatcher(UiDevice device) {
@@ -62,35 +60,4 @@ public class FailureWatcher extends TestWatcher {

        device.takeScreenshot(new File(pathname));
    }

    @Override
    public Statement apply(Statement base, Description description) {
        return new Statement() {

            @Override
            public void evaluate() throws Throwable {
                if (sHadFailedTestDeinitialization) {
                    Log.d(TAG, "Skipping due to a recent test deinitialization failure: " +
                            description.getDisplayName());
                    return;
                }

                try {
                    FailureWatcher.super.apply(base, description).evaluate();
                } catch (Throwable e) {
                    final String stackTrace = Log.getStackTraceString(e);
                    if (!stackTrace.contains(
                            "androidx.test.internal.runner.junit4.statement.RunBefores.evaluate")) {
                        // Test failed to deinitialize. Since the global state is probably
                        // corrupted, won't execute other tests.
                        Log.d(TAG,
                                "Detected an exception from test finalizer, will skip further "
                                        + "tests: " + stackTrace);
                        sHadFailedTestDeinitialization = true;
                    }
                    throw e;
                }
            }
        };
    }
}