qileilove

blog已经转移至github,大家请访问 http://qaseven.github.io/

Robotium针对只有apk包的测试方法

    我们在测试中往往得到的测试包只是一个apk文件,许多公司对于源码还是有所保留。为此我结合robotium官方的文档以及自己的实践写一个针对apk包的自动化测试教程,希望对这方面不了解的同学有所帮助。

  • 准备工作

  1. 掌握基本的robotium测试:参考Robotium环境搭建与新手入门教程
  2. 被测试工程:点击下载
  3. 重签名批处理文件:点击下载
  4. 签名,debug.keystore(位于虚拟机主目录下,例:C:\Users\Admin\.android)
  • 操作步骤

  1. 将例子程序拖到resign.bat文件上(确保例子程序、debug签名、resign.bat在同一文件夹中),完成后即可得到经过重新签名的apk文件了。注:重签名的方法有各种各样,比如官方提供的resign.jar工具
  2. 打开Eclipse,新建一个空的android应用程序,并且引入robotium.jar包
  3. 修改manifest.xml文件,加人instrumentation配置
  4. 新建一个junit测试类,代码如下:
    01package com.example.testapk;
    02 
    03import android.test.ActivityInstrumentationTestCase2;
    04 
    05import com.jayway.android.robotium.solo.Solo;
    06 
    07@SuppressWarnings({ "unchecked""rawtypes" })
    08public class Test extendsActivityInstrumentationTestCase2 {
    09private static final String LAUNCHER_ACTIVITY_FULL_CLASSNAME ="com.calculator.Main";
    10private static Class launcherActivityClass;
    11static {
    12try {
    13launcherActivityClass = Class
    14.forName(LAUNCHER_ACTIVITY_FULL_CLASSNAME);
    15catch (ClassNotFoundException e) {
    16throw new RuntimeException(e);
    17}
    18}
    19 
    20public Test() throws ClassNotFoundException {
    21super(launcherActivityClass);
    22}
    23 
    24private Solo solo;
    25 
    26@Override
    27protected void setUp() throws Exception {
    28solo = new Solo(getInstrumentation(), getActivity());
    29}
    30 
    31public void testDisplayBlackBox() {
    32solo.enterText(0"10");
    33solo.enterText(1"20");
    34solo.clickOnButton("Multiply");
    35assertTrue(solo.searchText("200"));
    36}
    37 
    38@Override
    39public void tearDown() throws Exception {
    40solo.finishOpenedActivities();
    41}
    42}
  5. 确保上述操作无误,即可点击测试用例执行测试了。

 

posted on 2014-05-15 21:16 顺其自然EVO 阅读(2322) 评论(1)  编辑  收藏 所属分类: android

评论

# re: Robotium针对只有apk包的测试方法[未登录] 2014-12-25 15:51 aaa

有些地方将的不详细啊,能具体说明一下instrumentation配置吗  回复  更多评论   


只有注册用户登录后才能发表评论。


网站导航:
 
<2024年4月>
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011

导航

统计

常用链接

留言簿(55)

随笔分类

随笔档案

文章分类

文章档案

搜索

最新评论

阅读排行榜

评论排行榜