【转】robotium搭建环境
上一篇 /
下一篇 2015-02-27 12:19:15
我们在测试中往往得到的测试包只是一个apk文件,许多公司对于源码还是有所保留。为此我结合robotium官方的文档以及自己的实践写一个针对apk包的自动化测试教程,希望对这方面不了解的同学有所帮助。
- 掌握基本的robotium测试:参考Robotium环境搭建与新手入门教程
- 被测试工程:点击下载
- 重签名批处理文件:点击下载
- 签名,debug.keystore(位于虚拟机主目录下,例:C:\Users\Admin\.android)
- 将例子程序拖到resign.bat文件上(确保例子程序、debug签名、resign.bat在同一文件夹中),完成后即可得到经过重新签名的apk文件了。注:重签名的方法有各种各样,比如官方提供的resign.jar工具
- 打开Eclipse,新建一个空的android应用程序,并且引入robotium.jar包
- 修改manifest.xml文件,加人instrumentation配置
- 新建一个junit测试类,代码如下:
package com.example.testapk; import android.test.ActivityInstrumentationTestCase2; import com.jayway.android.robotium.solo.Solo; @SuppressWarnings({ "unchecked", "rawtypes" }) public class Test extends ActivityInstrumentationTestCase2 { 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) { throw new RuntimeException(e); } } public Test() throws ClassNotFoundException { super(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, "20"); solo.clickOnButton("Multiply"); assertTrue(solo.searchText("200")); } @Override public void tearDown() throws Exception { solo.finishOpenedActivities(); } }
- 确保上述操作无误,即可点击测试用例执行测试了。
收藏
举报
TAG: