Robotium_RobotiumForAPKFiles (Use Robotium when only having apk)

http://code.google.com/p/robotium/wiki/RobotiumForAPKFiles

With Robotium it is possible to run test cases on applications where you only have the apk file.

For step by step instructions with images download this tutorial.

Introduction

The .apk file has to have the same signature as your test project. If you do not have the signature key of the .apk file then you need to remove the signature and resign it with you own key, android debug key can be used. A drag and drop java tool can be downloaded from here which strips the apk file from its signature and then signs it with your android debug key. If the new apk is not saved then try to run the re-sign tool as an administrator. In windows that would be done by right clicking the re-sign.jar and select run as administrator. In OS X it can be done by opening up the terminal and then "sudo java -jar re-sign.jar".

The android debug key is used by Eclipse when signing applications and test projects before installing them on the emulator/device. Many times it is easier to just use that key when resigning the apk.

Details

To make this work you need to know the package name and the launcher activity name. Those can be obtained by starting the application in the emulator and whatching the logs (adb logcat). The log shows what the package name and the activity name are. An example of how the log message can look like: "Starting activity: Intent { act=android.intent.action.MAIN cat=android.intent.category.LAUNCHER? flg=0x10200000 cmp=com.example.android.notepad/.NotesList"

That means that the package name (TARGET_PACKAGE_ID in the example below) is: com.example.android.notepad and the launcher activity name (LAUNCHER_ACTIVITY_FULL_CLASSNAME in the example below) is: com.example.android.notepad.NotesList

When you have that information you do the following:

In your test project's AndroidManifest.xml in Eclipse, set the target package to the package id you found above.

Write your test class like this: (the example here is for NewsRob)


package com.yourcompany.yourtestname;

import com.jayway.android.robotium.solo.Solo;

import android.test.ActivityInstrumentationTestCase2;

@SuppressWarnings("rawtypes")
public class ReallyBlackboxTest extends ActivityInstrumentationTestCase2 {

        private static final String LAUNCHER_ACTIVITY_FULL_CLASSNAME = "com.newsrob.DashboardListActivity";

        private static Class<?> launcherActivityClass;
        static{
                try {
                        launcherActivityClass = Class.forName(LAUNCHER_ACTIVITY_FULL_CLASSNAME);
                } catch (ClassNotFoundException e) {
                        throw new RuntimeException(e);
                }
        }
        
        @SuppressWarnings("unchecked")
        public ReallyBlackboxTest() throws ClassNotFoundException {
                super(launcherActivityClass);
        }
        
        private Solo solo;
        
        @Override
        protected void setUp() throws Exception {
                solo = new Solo(getInstrumentation(), getActivity());
        }

        public void testCanOpenSettings(){
                solo.pressMenuItem(0);
        }


 @Override
   public void tearDown() throws Exception {
                solo.finishOpenedActivities();

  }


}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值