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

This commit is contained in:
TreeHugger Robot
2020-02-13 16:01:03 +00:00
committed by Android (Google) Code Review
@@ -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;
}
}
};
}
}