mirror of
https://github.com/LawnchairLauncher/lawnchair.git
synced 2026-02-27 23:36:47 +00:00
Merge "Not crashing tests when a test fails to deinitialize" into ub-launcher3-master
This commit is contained in:
committed by
Android (Google) Code Review
commit
ae5e991f5e
@@ -184,16 +184,8 @@ public abstract class AbstractLauncherUiTest {
|
||||
|
||||
@After
|
||||
public void verifyLauncherState() {
|
||||
try {
|
||||
// Limits UI tests affecting tests running after them.
|
||||
mLauncher.waitForLauncherInitialized();
|
||||
} 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);
|
||||
}
|
||||
// Limits UI tests affecting tests running after them.
|
||||
mLauncher.waitForLauncherInitialized();
|
||||
}
|
||||
|
||||
protected void clearLauncherData() throws IOException, InterruptedException {
|
||||
|
||||
@@ -8,6 +8,7 @@ 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;
|
||||
@@ -15,6 +16,7 @@ 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) {
|
||||
@@ -60,4 +62,31 @@ 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 {
|
||||
base.evaluate();
|
||||
} catch (Throwable e) {
|
||||
if (!Log.getStackTraceString(e).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.
|
||||
sHadFailedTestDeinitialization = true;
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user