I have an Android JUnit test that runs fine when the emulator screen is unlocked but will fail if the screen is locked. Here's a sample that demonstrates the problem:
package com.example.helloandroid.test;
import com.example.helloandroid.HelloAndroid;
import android.test.ActivityInstrumentationTestCase2;
import android.view.KeyEvent;
import android.widget.EditText;
public class HelloAndroidTest extends
ActivityInstrumentationTestCase2<HelloAndroid> {
private HelloAndroid mActivity;
private EditText editText;
public HelloAndroidTest() {
super("com.example.helloandroid", HelloAndroid.class);
}
@Override
protected void setUp() throws Exception {
super.setUp();
mActivity = this.getActivity();
editText = (EditText)mActivity.findViewById
(com.example.helloandroid.R.id.editText);
}
public void testEditTextFormatting() {
this.sendKeys(KeyEvent.KEYCODE_1);
assertEquals("1", editText.getText().toString());
}
}
The application under test in this example is the Android Tutorial "Hello World" with the TextView replaced by an EditText field called editText.
Currently, I get around this problem in my application by having the app unlock the screen. However, this solution is sub-optimal because it forces the app to require DISABLE_KEYGUARD permissions, which it otherwise doesn't need.
I've searched the Internet multiple times over the past year and come up empty. Any suggestions? Thanks for your time!