Skip to content

Instantly share code, notes, and snippets.

@johngray1965
Created October 16, 2024 18:20
Show Gist options
  • Select an option

  • Save johngray1965/24d7a3f1e5ae5f0fc1adc24444fe12ac to your computer and use it in GitHub Desktop.

Select an option

Save johngray1965/24d7a3f1e5ae5f0fc1adc24444fe12ac to your computer and use it in GitHub Desktop.
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
}
}
}
}
@johngray1965
Copy link
Author

Note, Robolectic handles this now. Running this appears to be counterproductive.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment