2012-04-23 84 views
11

我试图用猴子练习工具来强调测试我的android应用程序。如何过滤猴子使用android.intent.category测试的特定活动?

默认情况下,该工具将根据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"/> 

我不想MySettings被猴子进行试验做运动有Intent.CATEGORY_LAUNCHER类别或Intent.CATEGORY_MONKEY活动。

在我的真实情况下,这是因为该活动执行注销。所以注销后无法重新登录,以便继续测试其余的屏幕,这是整个测试的想法。

./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 
.. 

应该拒绝而不是让我猜的。任何想法如何避免猴子进入我不想要的活动?

+0

你有没有试过使用'-c'来指定你想要的包?这可能是默认值不起作用,但自己指定它们(即使最后的值与默认值相同)也可以使用。如果这没有帮助,这感觉就像文档错误或“猴子”编码错误。 – CommonsWare 2012-04-23 17:45:28

+0

是'-c android.intent.category.LAUNCHER -c android.intent.category.MONKEY',但结果完全相同。我也尝试在我只想关注的模块中使用不同的类别'android.intent.category.TEST'(我添加到清单中,我也使用-c选项),但是同样的结果:( – felipe 2012-04-23 17:52:14

+0

)有没有找到解决这个问题?在这里同样的问题 – ben 2013-01-05 00:04:59

回答

4

我已经处理,这是通过将活动的以下内容的onCreate(...),你不希望猴子测试方式:

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

这样的活动立即如果猴子正在测试它,则退出。

+0

适合我。:) – 2014-06-19 16:13:00