Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to filter specific Activities to be tested by monkey using android.intent.category?

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?

like image 225
felipe Avatar asked Apr 23 '12 17:04

felipe


People also ask

What is CATEGORY in intent filter?

Categories are used for implicit Intents. So, If your Activity can be started by an implicit Intent when no other specific category is assigned to activity, activity's Intent filter should include this category. (even if you have other categories in the Intent filter).

What are the intent filters in Android?

An intent filter declares the capabilities of its parent component — what an activity or service can do and what types of broadcasts a receiver can handle. It opens the component to receiving intents of the advertised type, while filtering out those that are not meaningful for the component.

What is CATEGORY in intent?

Standard categories are defined in the Intent class as CATEGORY_name constants. The name assigned here can be derived from those constants by prefixing " android. intent. category. " to the name that follows CATEGORY_ . For example, the string value for CATEGORY_LAUNCHER is " android.


1 Answers

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.

like image 73
Brandon Avatar answered Oct 09 '22 18:10

Brandon