android / android-test

An extensive framework for testing Android apps
https://android.github.io/android-test
Apache License 2.0
1.16k stars 315 forks source link

ScreenOrientationRule does not restore the orientation if a test fails #2308

Open saket opened 2 weeks ago

saket commented 2 weeks ago

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))
}