diff --git a/library/core/src/test/java/com/google/android/exoplayer2/RobolectricUtil.java b/library/core/src/test/java/com/google/android/exoplayer2/RobolectricUtil.java index af2a0ef8c6..0b5740b72c 100644 --- a/library/core/src/test/java/com/google/android/exoplayer2/RobolectricUtil.java +++ b/library/core/src/test/java/com/google/android/exoplayer2/RobolectricUtil.java @@ -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) {