diff --git a/espresso/CHANGELOG.md b/espresso/CHANGELOG.md index 6c0f04959..3763cf58b 100644 --- a/espresso/CHANGELOG.md +++ b/espresso/CHANGELOG.md @@ -17,6 +17,7 @@ The following artifacts were released: **Bug Fixes** * Replace now-unnecessary reflection from TestLooperManagerCompat when using Android SDK 36 APIs +* Don't suppress AppNotIdleException if dumpThreadStates throws. **New Features** diff --git a/espresso/core/java/androidx/test/espresso/AppNotIdleException.java b/espresso/core/java/androidx/test/espresso/AppNotIdleException.java index f46c1bcfc..9799d2a5a 100644 --- a/espresso/core/java/androidx/test/espresso/AppNotIdleException.java +++ b/espresso/core/java/androidx/test/espresso/AppNotIdleException.java @@ -20,7 +20,6 @@ import android.os.Looper; import androidx.test.espresso.util.StringJoinerKt; -import androidx.test.internal.platform.util.TestOutputEmitter; import java.util.List; import java.util.Locale; @@ -31,7 +30,6 @@ public final class AppNotIdleException extends RuntimeException implements Espre private AppNotIdleException(String description) { super(description); - TestOutputEmitter.dumpThreadStates("ThreadState-AppNotIdleException.txt"); } /** diff --git a/espresso/core/java/androidx/test/espresso/IdlingPolicy.java b/espresso/core/java/androidx/test/espresso/IdlingPolicy.java index d737ed3e6..a250fcd35 100644 --- a/espresso/core/java/androidx/test/espresso/IdlingPolicy.java +++ b/espresso/core/java/androidx/test/espresso/IdlingPolicy.java @@ -20,6 +20,7 @@ import static androidx.test.internal.util.Checks.checkNotNull; import android.util.Log; +import androidx.test.internal.platform.util.TestOutputEmitter; import java.util.List; import java.util.concurrent.TimeUnit; @@ -58,7 +59,14 @@ public TimeUnit getIdleTimeoutUnit() { public void handleTimeout(List busyResources, String message) { switch (errorHandler) { case THROW_APP_NOT_IDLE: - throw AppNotIdleException.create(busyResources, message); + AppNotIdleException appNotIdleException = + AppNotIdleException.create(busyResources, message); + try { + TestOutputEmitter.dumpThreadStates("ThreadState-AppNotIdleException.txt"); + } catch (RuntimeException e) { + appNotIdleException.addSuppressed(e); + } + throw appNotIdleException; case THROW_IDLE_TIMEOUT: throw new IdlingResourceTimeoutException(busyResources); case LOG_ERROR: