Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Testing with Android Monkey.. stays on Preference screen?

Tags:

android

I have developed an app and have been using Monkey to test it.

My application has a main screen and a menu option which opens a preference screen. One thing I have realised though is that once monkey opens my preference screen, it tends to stay within the preference activity for a very long time. The only time it ever exits it is when it restarts my whole activity, and once it enters the preference activity it stays there again, vigorously testing my preference activity without exitting it.

This results in my preference activity getting a complete workout from monkey, but my main activity not receiving much attention from it. I know that the behaviour of monkey is completely random, but could it be that I am doing something wrong with my preference activity? Repeated testing from monkey has shown this behaviour to be consistent.

Below is the code for my preference activity :

    public class MyPreferences extends PreferenceActivity {
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);

            addPreferencesFromResource(R.xml.my_preference);
        }
   }

And my manifest declaration:

    <activity android:name="com.myapp.android.testapp.MyPreferences" 
    android:label="@string/preference_activity_title" 
    android:configChanges="orientation|keyboard|keyboardHidden" 
    android:screenOrientation="portrait"/>

Oh and I run monkey with the following code:

    adb shell monkey -p com.myapp.android.testapp -v 100000
like image 816
Coins Avatar asked Jun 08 '11 12:06

Coins


1 Answers

There is probably only one path out of your PreferenceActivity -- the BACK button. Hence, until the Monkey happens to bump the BACK button, the Monkey will test your PreferenceActivity.

One way to address this is to add CATEGORY_MONKEY to your main activities that you want to test (besides your CATEGORY_LAUNCHER one), and use the -c switch from time to time. This will keep the Monkey in your selected activities. Simply leave that category off the PreferenceActivity.

You could try increasing --pct-syskeys, which will increase the odds of BACK being pressed, though that affects all your activities, not just your PreferenceActivity.

like image 104
CommonsWare Avatar answered Nov 15 '22 06:11

CommonsWare