I'd like to test android's behavior on all possible combinations of the following "inputs":
- top activity's
setRequestedOrientation()
(15 possible values, not includingSCREEN_ORIENTATION_BEHIND
) Settings.System.ACCELEROMETER_ROTATION
(2 possible values)Settings.System.USER_ROTATION
(4 possible values)- device's physical orientation (queryable by
OrientationEventListener
) (4 possible quadrants)
Specifically, I want to see how the inputs affect the following "output":
getWindowManager().getDefaultDisplay()
.getRotation()
(4 possible values)
So this will require testing at least all 15*2*4*4=480
possible input states.
Additionally, since rotation behavior is often dependent on the history of the inputs (not just the current input values), I want to test (at least) all possible transitions from one input state to an "adjacent" input state, i.e. to an input state that differs from the given input state by one input parameter. The number of such input state transitions is:
(number of input states) * (number of states adjacent to a given input state) = (15*2*4*4) * ((15-1) + (2-1) + (4-1) + (4-1)) = 480 * 21 = 10080
Furthermore, sometimes output is dependent on the previous output as well as previous and current
input (e.g. SCREEN_ORIENTATION_LOCKED
, SCREEN_ORIENTATION_SENSOR_LANDSCAPE
).
The number of possible outputs for a given input state can be between 1 and 4,
so this multiplies the number of transitions that must be tested by up to 4:
10080 * 4 = 40320
That's a lot of transitions to test, so the testing would have to be programmatic/scripted. Three out of the four input params are straightforward to control programmatically; the one that's not straightforward to control is the device's physical orientation.
So, how would one go about scripting it? I can think of the following approaches.
Approach #1: Replace the (physical or emulated) device's accelerometer with a scriptable mock accelerometer for the duration of the test. But, if I understand correctly, mock accelerometers do not exist for android.
Approach #2: Use the android emulator, and script pressing of the "rotate counterclockwise" and "rotate clockwise" buttons using an interaction automation tool on the host machine (e.g. applescript / autohotkey / xdotool).
Any other ideas?