Created
October 16, 2024 18:20
-
-
Save johngray1965/24d7a3f1e5ae5f0fc1adc24444fe12ac to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class ResetChoreographerRule : TestRule { | |
| override fun apply( | |
| base: Statement?, | |
| description: Description? | |
| ): Statement = | |
| object : Statement() { | |
| override fun evaluate() { | |
| try { | |
| val uiDispatcher: AndroidUiDispatcher = ReflectionHelpers.getField(AndroidUiDispatcher.Main, "element") | |
| ReflectionHelpers.setField(uiDispatcher, "choreographer", Choreographer.getInstance()) | |
| } catch (e: Exception) { | |
| Timber.e(e, "Failed to reset Choreographer") | |
| } | |
| try { | |
| base?.evaluate() | |
| } finally { | |
| // Reset the Choreographer after the test | |
| } | |
| } | |
| } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note, Robolectic handles this now. Running this appears to be counterproductive.