2012-08-17 30 views
0

仍然相对绿色的东西,我试图找出是否有可能写的JUnit功能测试针对预构建的应用程序SANS源。我找到了重新签署应用程序的方法,但我想知道如何将它包含在Eclipse项目中作为我的测试的依赖项?写一个JUnit功能测试的预建的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. */ 
} 
+0

看起来不错,但是如何将apk包含在Eclipse项目中作为我的测试的依赖项?我是否将应用程序重命名为zip,并将其列为jar依赖项? – Cliff 2012-08-17 21:04:05

+1

您在Eclipse中不需要任何依赖项。只需将apk安装在测试设备上,另一方面,测试用例在运行时将无法加载测试活动。您可以使用命令'adb install '在您的测试设备上安装apk。 – 2012-08-18 07:36:13