문제

I'm trying to use Monkey debuggin tool (from adb) to stress test a part of my application. As Monkey acts in a total random way, I'd like it to concentrate on the part of code that might contain an error I'm looking for (very rare bug, and I don't know how to replicate it).

So, in my Main activity I have 6 buttons, each fires up a new activity. I'd like to set monkey to look only in one of those activities, and every activity accesible from it. I cannot find a reasonable way to do it.

I've tried the
adb shell monkey -p my.package.name -c android.intent.category.MONKEY 1000
and in my manifest file I've put in some activities, that I'm interested in:

        <intent-filter>
            <category android:name="android.intent.category.MONKEY"/>                
        </intent-filter>

But it didn't work. Monkey still fires up activities that are not categorized by this tag. It is crucial for Monkey to work in selected subactivities, because it wastes about 95% of time roaming through my app, outside of subactivities that I actually want to test.

Also I've tried some simple script to launch the desired subactivity, but with no success.

Looking for any help,
cheers,
kajman

도움이 되었습니까?

해결책

I have also had a bit of problems with constraining the monkey with categories. I think it is not intended to work as you assume. How it works then? I have no clear idea, just experimenting with it. The documentation is quite poor.

For your problem you could consider the following approaches

  1. Put your subactivities under one subpackage and permit access to only that subpackage with the -p option
  2. Add some constraints to your code that prevents the navigation inside the app. For example set the onClickListeners to do nothing or disable back button for the activity under test when some specific condition is met.

P.S. You can use adb shell am start in order to start the desired subactivity. Again poor documentation, no example, but the action is the name of the action you have defined inside intent-filter for the activity in your AndroidManifest. Name is the Activity name, for example

adb shell am start -a my.package.app.ACTION1 -n my.package.app/.sub.MyActivity

다른 팁

I know it is bit late but here is more robust way - use code like this:

ActivityManager activityManager;
activityManager =  (ActivityManager)getSystemService(Context.ACTIVITY_SERVICE);

if(!activityManager.isUserAMonkey()) {
    //stuff you want to execute anywhere but monkey test
});
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top