13

I'm trying to stress test my android application using the monkey exercise tool.

By default the tool will exercise activities having category Intent.CATEGORY_LAUNCHER or Intent.CATEGORY_MONKEY according to the doc.

package="my.android" 

    <activity android:name=".activities.MyApp">
        <intent-filter>
            <action android:name="android.intent.action.MAIN"/>
            <category android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>
    </activity>        
    <activity android:name=".activities.MyScreen">
        <intent-filter>
            <category android:name="android.intent.category.MONKEY"/>
        </intent-filter>
    </activity>
    <activity android:name=".activities.MySettings"/>

I do not want MySettings to be tested by Monkey.

In my real case, this is because that activity does the logout. So after logout there is no way to login back in order to keep testing the rest of the screens which is the whole idea of the test.

./adb shell monkey -p my.android -v 500
:Monkey: seed=0 count=500
:AllowPackage: my.android
:IncludeCategory: android.intent.category.LAUNCHER
:IncludeCategory: android.intent.category.MONKEY
..
    // Allowing start of Intent { cmp=my.android/.activities.MySettings} in package my.android
..

It should be rejecting instead of allowing I guess. Any idea how to avoid the monkey to get into activities I don't want to?

HitOdessit
  • 7,198
  • 4
  • 36
  • 59
felipe
  • 1,039
  • 1
  • 13
  • 27
  • Have you tried using `-c` to specify which packages you want? It may be that the defaults are not working, but specifying them yourself (even if, in the end, the values are the same as the defaults) works. If that does not help, this feels like either a documentation bug or a `monkey` coding bug. – CommonsWare Apr 23 '12 at 17:45
  • Yes `-c android.intent.category.LAUNCHER -c android.intent.category.MONKEY` but exactly the same result. I also tried to use a different category `android.intent.category.TEST` in the modules I wanted to focus only (I added to the manifest and I was using -c option too) but again, same result :( – felipe Apr 23 '12 at 17:52
  • Did you ever find a solution to this ? Same problem here – ben Jan 05 '13 at 00:04

1 Answers1

7

The way I've handled this is by adding the following into onCreate(...) of the activities that you do not want the monkey to test:

if (ActivityManager.isUserAMonkey()) { finish(); }

That way the activity immediately exits if it is being tested by a monkey.

Brandon
  • 1,164
  • 14
  • 22