【问题标题】:Write a JUnit functional test for a prebuilt apk为预构建的 apk 编写 JUnit 功能测试
【发布时间】:2012-08-18 02:51:05
【问题描述】:

对于事情仍然相对绿色,我试图弄清楚是否可以针对预构建的应用程序无源代码编写 JUnit 功能测试。我找到了一种重新签署应用程序的方法,但我想知道如何将它作为我的测试的依赖项包含在 Eclipse 项目中?

【问题讨论】:

    标签: android dependencies apk


    【解决方案1】:

    是的,这确实可以使用 Java 反射。

    除此之外,您可能需要退出您要测试的应用程序。从您的设备下载它(例如,使用 AppMonster 应用程序),使用 resign.jar (http://www.troido.de/re-sign.jar) 将其退出,然后使用 adb 重新安装。

    之后,一切都应该正常了。

    @SuppressWarnings("rawtypes")
    public class YourTestSuite extends ActivityInstrumentationTestCase2 {
    
        /** Package ID of the app under test. */
        private static final String TARGET_PACKAGE_ID = "com.something";
    
        /** ID of the app under test's main activity. */
        private static final String LAUNCHER_ACTIVITY_FULL_CLASSNAME = "com.something.HomeActivity";
    
        /** Launcher activity class. */
        private static Class<?> launcherActivityClass;
    
        /** Static code to find the activity class. */
        static {
            try {
                launcherActivityClass = Class
                    .forName(LAUNCHER_ACTIVITY_FULL_CLASSNAME);
            }
    
            catch (ClassNotFoundException e) {
                throw new RuntimeException(e);
            }
        }
    
        /**
         * Constructor
         * 
         * @throws ClassNotFoundException
         */
        @SuppressWarnings("unchecked")
        public YourTestSuite() throws ClassNotFoundException {
            super(TARGET_PACKAGE_ID, launcherActivityClass);
        }
    
        /* Your test code comes here. */
    }
    

    【讨论】:

    • 看起来不错,但是如何将 apk 包含在 Eclipse 项目中作为我的测试的依赖项?我是否将其从 app 重命名为 zip 并将其列为 jar 依赖项?
    • Eclipse 中不需要任何依赖项。只需在您的测试设备上安装 apk,否则您的测试用例将无法在运行时加载被测活动。您可以使用命令“adb install ”在您的测试设备上安装 apk。
    猜你喜欢
    • 2013-01-14
    • 1970-01-01
    • 2018-11-27
    • 1970-01-01
    • 2013-08-02
    • 1970-01-01
    • 1970-01-01
    • 2021-02-03
    • 1970-01-01
    相关资源
    最近更新 更多