Use robotium when only having APK

Source: Internet
Author: User
Introduction

The. APK file has to have the same signature as your test project. if you do not have the signature key of. 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 wocould 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. Reset 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("unchecked")public class ReallyBlackboxTest extends ActivityInstrumentationTestCase2 {        private static final String TARGET_PACKAGE_ID = "com.newsrob";        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(TARGET_PACKAGE_ID, 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();  }}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.