I’m using robolectric to make my android unit tests fast enough to be useful. I want to test that code I’ve written works while the screen orientation is changing to simulate a common real world use case.
Specifically what I’m testing is an asynchronous http call to a server with some xml parsed after the result is fetched. I have the unit test for all that working great but can’t figure out how to simulate the screen rotation. Any state change that causes the activity to recreate itself is fine, it doesn’t necessarily have to be screen rotation.
A solution that uses the emulator is not an option as I run my tests several times per minute and they must run under 2 seconds. I would also like this to work with roboguice if possible.
Thanks.
What Android API level are you compiling against? If it’s 3.0 or above you could try
Activity.recreate(). The documentation states:Haven’t tried it myself though.