android-test icon indicating copy to clipboard operation
android-test copied to clipboard

ScreenOrientationRule does not restore the orientation if a test fails

Open saket opened this issue 1 year ago • 0 comments

Does ScreenOrientationRule need a try block around its statement evaluation?

Current:

val orientationToRestore = defaultOrientation ?: getCurrentOrientation()
statement.evaluate()
onDevice().perform(setScreenOrientation(orientationToRestore))

Proposed:

val orientationToRestore = defaultOrientation ?: getCurrentOrientation()
try {
  statement.evaluate()
} finally {
  onDevice().perform(setScreenOrientation(orientationToRestore))
}

saket avatar Nov 08 '24 18:11 saket