Interrupt the test thread for uncaught errors

This makes assertion errors in code running on the Looper less easy to miss.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=184294290
This commit is contained in:
andrewlewis 2018-02-02 09:41:31 -08:00 committed by Andrew Lewis
parent 451721d4a7
commit 0b2497799f

View file

@ -117,7 +117,14 @@ public final class RobolectricUtil {
}
}
if (!isRemoved) {
target.dispatchMessage(pendingMessage.message);
try {
target.dispatchMessage(pendingMessage.message);
} catch (Throwable t) {
// Interrupt the main thread to terminate the test. Robolectric's HandlerThread will
// print the rethrown error to standard output.
Looper.getMainLooper().getThread().interrupt();
throw t;
}
}
}
if (Util.SDK_INT >= 21) {