I'm writing a test using ActivityInstrumentationTestCase2.
When the emulator is open and the activity can get the foreground, my tests works perfectly.
When I start the tests wit the phone locked, the activity is not created. This seems to "make sense" since there is no reason to load an activity if it can not get the foreground (the phone is locked!). However, when running a test suite, this leads to false negatives...
Here is a sample test
public void testSplashscreenRedirectsSomewhereAfterTimeout() throws Exception {
Instrumentation.ActivityMonitor monitor = getInstrumentation().addMonitor(SomeActivity.class.getName(), null, false);
getActivity(); // to make sure that the activity gets launched
Activity activity = monitor.waitForActivityWithTimeout(10000); // waiting for the other activity
assertNotNull("BaselineActivity was not called", activity);
}
when the phone is locked, getActivity() returns the correct activity but its onCreate() method is never called.
Any way to get the tests to work even if the screen is locked?