多测师是一家拥有先进的教学理念,强大的师资团队,业内好评甚多的接口自动化测试培训机构!

17727591462

联系电话

您现在所在位置:接口自动化测试培训 > 新闻资讯

Robotium测试单独APK包-自动化测试

更新时间:2022-04-28 09:12:19 作者:多测师 浏览:241

  在做Android测试时,很多公司都不给源代码,仅仅只有apk包,这个给测试带来了一定的困难。Robotium本身支持对单独apk包进行测试,可能某些时候会出现一些小问题。下面是我使用robotium测试单独包的过程。仅供参考。

Robotium测试单独APK包-自动化测试

  1、下载AndroidCalculator.apk包,可以到官方网站去下载。

  2、启动eclipse,建立android工程,这步骤就不详细描述了。

  3、在工程中编写代码:

  package com.calculator.test;

  import android.test.ActivityInstrumentationTestCase2;

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

  public class TestAPK extends ActivityInstrumentationTestCase2{

  private static final String TARGET_PACKAGE_ID="com.calculator";

  private static final String LAUNCHER_ACTIVITY_FULL_CLASSNAME="com.calculator.Main";

  private static Class launcherActivityClass;

  static{

  try{

  launcherActivityClass = Class.forName(LAUNCHER_ACTIVITY_FULL_CLASSNAME);

  }catch(ClassNotFoundException e){

  new RuntimeException(e);

  }

  }

  public TestAPK() throws ClassNotFoundException{

  super(TARGET_PACKAGE_ID, launcherActivityClass);

  }

  private Solo solo;

  @Override

  protected void setUp() throws Exception{

  solo = new Solo(getInstrumentation(), getActivity());

  }

  public void testDisplayBlackBox(){

  solo.enterText(0, "10");

  solo.enterText(1, "30");

  solo.clickOnButton("Multiply");

  assertTrue(solo.searchText("300"));

  }

  @Override

  public void tearDown() throws Exception{

  solo.finishOpenedActivities();

  }

  }

  4、启动模拟器AVD

  5、重签名AndroidCalculator.apk,一般使用工具,使用工具为:re-sign.jar,将签名修改为debug模式

  6、启动cmd,输入adb devices,查看设备连接状态,连接正常,进行第7步

  7、安装重新签名后的包,adb install AndroidCalculator_debug.apk

  8、运行程序,Run as --> Android Junit Test.打开模拟器,验证是否正常。

  我遇到的坑有:

  1、测试时没有模拟用户输入,我的方式是:重新启动后,添加了@SuppressWarnings("rawtypes"),就可以了。

  2、重新签名,re-sign有时候重新签名不成功。

  以上内容为大家介绍了自动化测试中的Robotium测试单独APK包,本文由多测师亲自撰写,希望对大家有所帮助。了解更多自动化测试相关知识:https://www.aichudan.com/xwzx/

联系电话

17727591462

返回顶部